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即可~

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐