小编Moh*_*vad的帖子

如何使用spring AOP拦截所有带有@Repository注解的存储库类

我试图拦截我的BaseRepostitary文件中所有返回的列表。这样我就可以找到列表中必须使用此decrypt方法解密的名称。以下是我的方面类

@Aspect
@Service
public class DecryptionAspect {

 @AfterReturning(value = "execution(java.util.List *(..)) "
        + "&& target(org.springframework.stereotype.Repository)) ", returning = "list")
    public void decrypt(List list) throws Exception
    {
        //Do decryption here for the names inside the list
    }

}
Run Code Online (Sandbox Code Playgroud)

但问题是,decrypt当我的存储库类受到攻击时,该方法不会触发。所以我的表达有问题。我知道我可以通过包名称来定位存储库类。但我有很多存储库类,并且我已经@Repository为这些类提供了注释。所以我希望这个 AOP 表达式能够识别哪些类具有@Repository注释,并拦截存储库类中的所有列表项。那么如何重写我的表达式。提前致谢!

java aop spring

5
推荐指数
1
解决办法
1032
查看次数

标签 统计

aop ×1

java ×1

spring ×1