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

问题描述

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

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 批注.因此,我希望此AOP表达式能够识别出所有存在 @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批注的存储库类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:49