public class LogNotificationThrowsAdvice implements ThrowsAdvice {
private LoggerUtil loggerUtil;
public void setLoggerUtil(LoggerUtil loggerUtil) {
this.loggerUtil= loggerUtil;
}
public void afterThrowing(Exception ex) throws Throwable {
this.loggerUtil.createLogger()
}
}<bean id="logNotificationThrowsAdvice "
class="com.LogNotificationThrowsAdvice">
<property name="loggerUtil"><ref bean="loggerUtil"/></property>
</bean><bean id="loggerUtil" class="com.LoggerUtil"/>
<bean id="accountManagerBeanNameProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames"><value>accountManagerTarget</value></property>
<property name="interceptorNames">
<list>
<value>logNotificationThrowsAdvice</value>
</list>
</property>
</bean>accountManagerBeanNameProxyCreator是你系统中原来的业务方法。
通过修改配置文件,你不需要改原系统代码,就可以通过spring的拦截机制增加Logger的功能
private LoggerUtil loggerUtil;
public void setLoggerUtil(LoggerUtil loggerUtil) {
this.loggerUtil= loggerUtil;
}
public void afterThrowing(Exception ex) throws Throwable {
this.loggerUtil.createLogger()
}
}<bean id="logNotificationThrowsAdvice "
class="com.LogNotificationThrowsAdvice">
<property name="loggerUtil"><ref bean="loggerUtil"/></property>
</bean><bean id="loggerUtil" class="com.LoggerUtil"/>
<bean id="accountManagerBeanNameProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames"><value>accountManagerTarget</value></property>
<property name="interceptorNames">
<list>
<value>logNotificationThrowsAdvice</value>
</list>
</property>
</bean>accountManagerBeanNameProxyCreator是你系统中原来的业务方法。
通过修改配置文件,你不需要改原系统代码,就可以通过spring的拦截机制增加Logger的功能
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货