解决 Cannot find current proxy: Set ‘exposeProxy‘ property on Advised to ‘true‘ to make it available,

1、报错日志信息 :Cannot find current proxy: Set 'exposeProxy' property on Advised to 'true' to make it available,

2、报错场景
因为使用了AOP中的获取代理对象,代码如下

IVoucherOrderService proxy = (IVoucherOrderService) AopContext.currentProxy();

3、报错原因
因为Spring默认不允许获取代理对象,如果使用需要手动开启

4、解决方式

1、引入依赖

<dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId>
</dependency>

2、开启AOP获取(在SpringBoot启动类或者配置类上加)

@EnableAspectJAutoProxy(exposeProxy = true)

默认是false,不允许获取代理对象,我们改成true即可~


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部