Aspectj and catching private or inner methods

前端 未结 1 1385
不思量自难忘°
不思量自难忘° 2020-12-09 14:10

I\'ve configureg AspectJ with Spring and it works fine when \"catching\" public methods called from out of the class. Now I want do something like this:

publ         


        
相关标签:
1条回答
  • 2020-12-09 14:23

    Yes it is easy to catch private methods with AspectJ.

    An example that prints a sentence before all private methods:

     @Pointcut("execution(private * *(..))")
     public void anyPrivateMethod() {}
    
     @Before("anyPrivateMethod()")
     public void beforePrivateMethod(JoinPoint jp) {
         System.out.println("Before a private method...");
     }
    

    If you are familiar with Eclipse, I recommend to develop AspectJ with STS or only install the AJDT plugin.

    More information about Spring AOP capabilities can be found in the Spring reference documentation here.

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