Spring AOP 不起作用的解决办法

有可能出现的问题:

1:execution表达式写错了。

2:配置文件或配置类中忘记添加<aop:aspectj-autoproxy/>。

3:如果切入点没有实现接口需要使用cglib动态代理,<aop:aspectj-autoproxy proxy-target-class="true"/>

4:<context:component-scan 配置的问题导致无法动态代理,具体请参考官方文档。

一般情况下主配置文件要排除@Controller注解,webmvc配置里应该只包含@Controller注解。

如果我们要切入Controller,我们需要在webmvc配置里面加入<aop:aspectj-autoproxy proxy-target-class="true"/>。

如果我们要切入其他如Service,我们需要在主配置里面加入<aop:aspectj-autoproxy proxy-target-class="true"/>。

如果我们既要切入Controller又要切入Service,两个配置都需要加入<aop:aspectj-autoproxy proxy-target-class="true"/>。这个问题比较奇怪,目前还不知道解决方法。

猜你喜欢

转载自ihansel.iteye.com/blog/2293780