AspectJ pointcut for annotated PRIVATE methods

前端 未结 2 1270
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 22:39

I want to create a Pointcut for private methods that are annotated with a specific annotation. However my aspect is not triggered when the annotation is on a private method

相关标签:
2条回答
  • 2020-12-14 23:08

    8. Aspect Oriented Programming with Spring

    Due to the proxy-based nature of Spring's AOP framework, protected methods are by definition not intercepted, neither for JDK proxies (where this isn't applicable) nor for CGLIB proxies (where this is technically possible but not recommendable for AOP purposes). As a consequence, any given pointcut will be matched against public methods only!

    If your interception needs include protected/private methods or even constructors, consider the use of Spring-driven native AspectJ weaving instead of Spring's proxy-based AOP framework. This constitutes a different mode of AOP usage with different characteristics, so be sure to make yourself familiar with weaving first before making a decision.

    0 讨论(0)
  • 2020-12-14 23:22

    Switch to AspectJ and use a privileged aspect. Or change the design of your application so as to accomodate Spring AOP's limitations. My choice would be the much more powerful AspectJ.

    0 讨论(0)
提交回复
热议问题