如何使用spring AOP拦截所有具有@Repository注解的存储库类 [英] How to intercept all the repository classes which has @Repository annotation using spring AOP

查看:47
本文介绍了如何使用spring AOP拦截所有具有@Repository注解的存储库类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to intercept all the returning List from my BaseRepostitary files. So that i can find the names inside that lists which has to be decrypted using this decrypt method. Following is my Aspect Class

@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
    }

}

但问题是这个 decrypt 方法在我的 Repository 类被命中时没有触发.所以我的表达有问题.我知道我可以通过包名称定位 Repository 类.但是我有很多 Repository 类,并且我已经为这些类提供了 @Repository 注释.所以我希望这个 AOP 表达式能够识别哪些类具有 @Repository 注释,并拦截 Repository 类中的所有 List 项.那么如何改写我的表达.提前致谢!

But the problem is this decrypt method is not triggering at the time of my Repository classes gets hit. So something is wrong in my expression. I know i can target the Repository class by the package name. But i have many Repository classes and i have given the @Repository annotation for that classes. So i want this AOP expression to identify which are all the classes have @Repository annotation present and intercept all the List items inside the Repository classes. So how to rewrite my expression. Thanks in advance!

推荐答案

我终于明白了!

@AfterReturning(value="execution(* *..*Repository.*(..))",returning="list")
  public void decrypt(List list) throws Exception
    {
        //Do decryption here for the names inside the list
    }

}

这篇关于如何使用spring AOP拦截所有具有@Repository注解的存储库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆