Spring AOP @Aspect没反应的处理

1,043 阅读1分钟

写了一个切面类,使用了 @Aspect@Component 注解。在配置类上使用 @Configuration@EnableAspectJAutoProxy 注解。

在测试时发现没有任何反应,经过网上查询,解决了问题。

方案如下:

  • 在使用EnableAspectJAutoProxy注解时要加上proxyTargetClass=true的参数,默认为false。 @EnableAspectJAutoProxy(proxyTargetClass=true)

  • 如果是使用的xml配置文件,使用以下配置项: <aop:aspectj-autoproxy proxy-target-class="true" />