报错信息:
java.lang.IllegalStateException: Cannot find current proxy: Set ‘exposeProxy’ property on Advised to ‘true’ to make it available, and ensure that AopContext.currentProxy() is invoked in the same thread as the AOP invocation context.
场景:
Spring Boot 中,使用
AopContext.currentProxy()
,用来解决调用类内方法导致事务失效的问题
解决方法:
- 添加 aspectjweaver 依赖
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
- 启动类上加注解 @EnableAspectJAutoProxy(exposeProxy = true)
@EnableAspectJAutoProxy(exposeProxy = true)
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application .class, args);
}
}
版权声明:本文为Cey_Tao原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。