public interface GoodsBiz {
public void testLog(); 其它方法省略。。
}
public class GoodsBizImpl implements GoodsBiz {
public void testLog() {
System.out.println("--------GoodsBizImpl----------testLog()---------start-----------------------");
} 其它方法省略。。
}
action中:
public ActionForward toGoodsOnSale(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
this.goodsBiz.testLog();
return mapping.findForward("toGoodsOnSale");
}
日志类:
public class LogAdvice implements AfterReturningAdvice {
public void afterReturning(Object returnValue, Method m, Object[] arg,
Object target) throws Throwable {
System.out.println("业务日志\n "+
" 时间:"+new Date()+"\n"
+"业务类:"+target.getClass().getName()+"\n"
+"业务方法"+m.getName()+"\n"
+"参数:"+"("+Arrays.toString(arg)+")\n"
+"返回值"+returnValue
);
}
}
spring配置文件相关代码:
<bean id="logAdvice" class="com.aop.LogAdvice"/>
<bean id="goodsBizTarget" class="com.biz.impl.GoodsBizImpl"/>
<bean id="goodsBizProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.biz.GoodsBiz</value>
</property>
<property name="interceptorNames">
<list>
<value>logAdvice</value>
</list>
</property>
<property name="target" ref="goodsBizTarget"></property>
</bean>程序用tomcat发布1:在IE中运行后控制台结果如下:(没有任何异常,但不输出日志类的信息)
--------GoodsBizImpl----------testLog()---------start-----------------------2:直接在Myeclipse7中运行下面的main方法:
public static void main(String[] args) {
ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
GoodsBiz b=(GoodsBiz)context.getBean("goodsBizProxy");
b.testLog();
}
结果如下:(输出了日志类的信息)
log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
log4j:WARN Please initialize the log4j system properly.
--------GoodsBizImpl----------testLog()---------start-----------------------
业务日志
时间:Fri Jun 12 11:38:54 CST 2009
业务类:$Proxy2
业务方法testLog
参数:([])
返回值null
怎么样可以在IE中运行时也输出日志类信息呢?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货