Spring AOP Advice on Annotated Controllers

前端 未结 3 1182
有刺的猬
有刺的猬 2020-12-02 23:44

I am trying to use AOP to do some processing after an annotated controller. Everything is running with no errors, but the advice is not being executed.

Here is the

3条回答
  •  清歌不尽
    2020-12-03 00:12

    I had the same problem where advice for Repository was working, but advice for Controller was not. Finally I found a solution. In short, you need to make sure your AOP definition is loaded in Servlet context, not a different context.

    In my case, my Spring AOP definition is defined in tools-config.xml. After moving it from here

    
        contextConfigLocation
        classpath:spring/tools-config.xml
    
    
    
        org.springframework.web.context.ContextLoaderListener
    
    

    to here,

    
        petclinic
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:spring/mvc-core-config.xml, classpath:spring/tools-config.xml
        
        1
    
    

    the advice for Controller is working.

提交回复
热议问题