AOP代理
今天在使用事务注解@Transactional 对线程池添加事务时,需要通过动态代理来调用对应的方法,调用中报错信息如下:
java.lang.IllegalStateException: Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it available.
at org.springframework.aop.framework.AopContext.currentProxy(AopContext.java:64)
问题原因:生成代理类时使用的是AopContext.currentProxy()方法,但未进行配置。
解决方式:在类上添加如下注解
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)