Results 1 to 3 of 3

Thread: aop around controllers

  1. #1
    Join Date
    Jun 2012
    Posts
    12

    Default aop around controllers

    Hi all, I created a custom annotation for enabling the execution of a certain aspect.

    Code:
    <bean id="profilingAspect" class="com.domosafety.template.aspects.ProfilingAspect" />
    
    <aop:config>
    
    <aop:pointcut id="profileAnnotatedTypes" expression="within(@com.domosafety.template.annotations.Profile *) and execution(* *(..))" />
    			<aop:pointcut id="profileAnnotatedMethods" expression="@annotation(com.domosafety.template.annotations.Profile) and execution(* *(..))" />
    
    			<aop:aspect id="aspectProfiling" ref="profilingAspect">
    				<aop:around method="doBasicProfiling" pointcut-ref="profileAnnotatedTypes" />
    				<aop:around method="doBasicProfiling" pointcut-ref="profileAnnotatedMethods" />
    			</aop:aspect>
    
    		</aop:config>
    It should run around each method I annotate, and it does, except for the controllers.
    How can I target the controllers using aop instead of interceptors?
    Thank you

    Daniel

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    You are using AOP make sure that that is defined in the SAME context as you are defining your beans in. I suspect that you are defining this configuration in your root context (ContextLoaderListener) and expect it to work in beans defined by the servlet context (DispatcherServlet) that isn't going to work. AOP defined in the parent doesn't affect beans in the child context (and vice-versa).

    Next to that make sure you are using class proxies else it wont work as your @Controllers probably don't implement an interface.
    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
    Jun 2012
    Posts
    12

    Default

    Hi Marten, you're right, i didn't import my aop configuration in the mvc context (Servlet) but only in the application context(listener).
    Now it does work as expected.
    Thank you

    Daniel

Posting Permissions

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