Results 1 to 5 of 5

Thread: AOP not working for Controllers

  1. #1
    Join Date
    Dec 2010
    Location
    India
    Posts
    16

    Question 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. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    Is it in the same context (ie the servlet and not the contextloaderlistener)?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Dec 2010
    Location
    India
    Posts
    16

    Default

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

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    aop only works for beans in the same applicationcontext, the contextloaderlistener and dispatcherservlet both have a seperate context. Load the aop in the dispatcherservlet.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Dec 2010
    Location
    India
    Posts
    16

    Thumbs up

    It is working now. Thank you.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •