Spring提供可以根据beanName匹配后进行自动代理的解决方法:
示例如下:
系统日志记录功能模块:
<bean id="autoActionLogInterceptor"
class="*.*.*.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Action</value><!--代理所有action-->
</list>
</property>
<property name="interceptorNames">
<list>
<value>actionAfter</value>
<value>actionThrow</value>
<value>actionBefore</value>
</list>
</property>
</bean>
切面配置:
<bean id="actionAfter" class="*.*.*.aspect.advice.ActionLogAfterAdvice">
<property name="logService">
<ref bean="logService" />
</property>
</bean>
<bean id="actionThrow" class="*.*.*.aspect.advice.ActionLogThrowAdvice">
<property name="logService">
<ref bean="logService" />
</property>
</bean>
<bean id="actionBefore" class="*.*.*.aspect.advice.ActionLogBeforeAdvice">
<property name="logService">
<ref bean="logService" />
</property>
<property name="tellerAuthorizationUtil">
<ref bean="tellerAuthorizationUtil" />
</property>
</bean>
public class ActionLogThrowAdvice implements ThrowsAdvice {
Logger logger = Logger.getLogger(this.getClass());
LogService logService;
public LogService getLogService() {
return logService;
}
public void setLogService(LogService logService) {
this.logService = logService;
}
public void afterThrowing(Method m,Object[] args,Object target,Exception ex){
// String className=target.getClass().getName();
// String methodName=m.getName();
ServiceRequest request=(ServiceRequest)args[0];
Object tellerObj = request.getSessionDTO();
if(tellerObj!=null){
if(tellerObj instanceof TellerOpLogDTO){
TellerOpLogDTO tellerOpLog=(TellerOpLogDTO)tellerObj;
tellerOpLog.setRequestResult("failure");
tellerOpLog.setErrorDescription(ex.getMessage());
try {
logService.recordTellerOpLog(tellerOpLog);
} catch (Exception e) {
this.logger.error("ActionLogThrowAdvice.afterThrowing写日志时发生错误",e);
}
}
}
}
}
相关推荐
NULL 博文链接:https://tomboxfan.iteye.com/blog/350398
3.1.2 Spring的AOP实现 3.2 创建通知 3.2.1 前置通知 3.2.2 后置通知 3.2.3 环绕通知 3.2.4 异常通知 3.2.5 引入通知 3.3 定义切入点 3.3.1 在Spring中定义切入点 3.3.2 ...
BeanNameAutoProxyCreator 7.9.1.2. DefaultAdvisorAutoProxyCreator 7.9.1.3. AbstractAdvisorAutoProxyCreator 7.9.2. 使用元数据驱动的自动代理 7.10. 使用TargetSources 7.10.1. 热交换目标源 7.10.2. 池化目标...
BeanNameAutoProxyCreator DefaultAdvisorAutoProxyCreator <br> 持久层 来看看 Spring 的 IoC 容器与 AOP 框架如何应用于持久层,包括了资料库、交易等相关议题。 资料库存取 Spring ...
6.1.3 AOP的实现者 6.2 基础知识 6.2.1 带有横切逻辑的实例 6.2.2 JDK动态代理 6.2.3 CGLib动态代理 6.2.4 AOP联盟 6.2.5 代理知识小结 6.3 创建增强类 6.3.1 增强类型 6.3.2 前置增强 6.3.3 后置增强 6.3.4 环绕...
6.1.3 AOP的实现者 6.2 基础知识 6.2.1 带有横切逻辑的实例 6.2.2 JDK动态代理 6.2.3 CGLib动态代理 6.2.4 AOP联盟 6.2.5 代理知识小结 6.3 创建增强类 6.3.1 增强类型 6.3.2 前置增强 6.3.3 后置增强 6.3.4 环绕...
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <!-- 指定对满足哪些bean name的bean自动生成业务代理 --> <!-- 下面是所有需要自动创建事务代理的bean--> ...
nested exception is java.lang.AbstractMethodError: org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator.postProcessAfterInstantiation(Ljava/lang/Object;Ljava/lang/String;)Z at org....
Spring的Ioc Spring的AOP , AspectJ Spring的事务管理 , 三大框架的整合 目录 1.1 Spring 框架学习路线:..........................................................................................................
BeanNameAutoProxyCreator BeanNameAware BeanNameUrlHandlerMapping BeanNameViewResolver BeanNotOfRequiredTypeException BeanPostProcessor BeanPropertyBindingResult BeanPropertySqlParameterSource ...
Not Using Commons Logging ................................................................... 12 Using SLF4J ..............................................................................................
Not Using Commons Logging ................................................................... 12 Using SLF4J ..............................................................................................