Spring AOP: logging and nested-methods

后端 未结 2 1885
旧时难觅i
旧时难觅i 2021-02-09 12:08

I have written a simple Spring2.5 app to demo/test AOP; specifically, I want to log the entry and exit of every method of every class in a specific package. This is what I have

2条回答
  •  不要未来只要你来
    2021-02-09 12:54

    You are using spring aop for aspect support. Spring aop will work only on spring beans. So, the pointcut does not work on the actual class instance i.e. when the controller calls any of its public or private method. In order to log all the methods in the controller, you need to use AspectJ for your aop support by enabling either load time or compile time weaving of all the classes that you want to intercept. Edit:

    You would need the following for load time weaving :

    aop.xml

        
        
            
            
        
        
            
            
        
      
    

    This implies weaving in all your files ('within=*', modify as you wish) with the aspect/s specified. On load time you should see verbose information on weaving of classes.

    Configurations in the spring configurations :

    
    

    Notice the weaving class has to be in the server library path and NOT your application path.

    The above configurations should do what you are looking out to do.

提交回复
热议问题