Announcement Announcement Module
Collapse
No announcement yet.
AOP not working for Controllers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP not working for Controllers

    Hi all,
    I am newbie to AOP, and i want to have around advice for methods in controller. My interceptor method is not invoked for controllers, however, it works for other packages. Please let me know if I am doing something wrong.

    This is my controller:
    Code:
    @Controller
    public class HomeController {
    	@RequestMapping("/home.htm")
    	public String redirect(HttpServletRequest request) {
    		return "home";
    	}
    
    }
    Code:
    @Aspect
    public class LoggingInterceptor {
    	@Around("execution(* com.somepack.controller..*.*(..))")
    	public Object invokeMethod(ProceedingJoinPoint pjp) throws Throwable  {
                    ...
                    o = pjp.proceed();
                    ...
    		return o;
    	}
    
    }
    And configuration as:

    Code:
         <bean id=" loggingInterceptor" class="com.somepack.util.LoggingInterceptor" />
    
    	<aop:aspectj-autoproxy>
                 <aop:include name="loggingInterceptor" />
            </aop:aspectj-autoproxy>
    Interceptor method is not invoked for "redirect" method of controller.
    Please let me know if I am doing something wrong.

  • #2
    Is it in the same context (ie the servlet and not the contextloaderlistener)?

    Comment


    • #3
      I have created a seperate file for AOP (beansdefinition_aop.xml) and I am loading it using contextloaderlistener.

      Comment


      • #4
        aop only works for beans in the same applicationcontext, the contextloaderlistener and dispatcherservlet both have a seperate context. Load the aop in the dispatcherservlet.

        Comment


        • #5
          It is working now. Thank you.

          Comment

          Working...
          X