Announcement Announcement Module
Collapse
No announcement yet.
aop around controllers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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

      Comment

      Working...
      X