SpringAop、嵌套调用失效、解决办法

一、加入注解

@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)

二、获取当前代理的接口

public interface ICurrentAopProxyService<T> {
    default T getCurrentProxyService() {
        return (T) AopContext.currentProxy();
    }
}

三、需要嵌套调用的Service实现它

在这里插入图片描述

四、调用的时候改写代码

通过getCurrentProxyService()去调用需要被嵌套生效的aop的方法

    public SysMerchantVersion selectByMerchantId(Long merchantId) {
        return getCurrentProxyService().getOne(new QueryWrapper<SysMerchantVersion>()
                .lambda()
                .eq(SysMerchantVersion::getMerchantId, merchantId));
    }

版权声明:本文为weixin_46496706原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。