Announcement Announcement Module
No announcement yet.
AOP advice triggered multiple times Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP advice triggered multiple times


    I have a situation when a class can get proxies multiple times to support multiple advices and in this case advices are getting triggered multiple times. Here is an example:

      <aop:pointcut id="serviceMethodExecution" expression="execution(* com.mycompany.service.*.*(..))" />
      <aop:aspect ref="AfterAdviceBean">
         <aop:after pointcut="execution(* com.mycompany.service.ServiceX.someMethod(..))" method="doSomething(org.aspectj.lang.JoinPoint)"/>
    here ServiceX.someMethod is proxied twice and I guess due to which the doSomething(JoinPoint) after-advice gets triggered twice.

    Is there a way to prevent this, or to make the second aop:config reuse the proxy for ServiceX that was created as part of serviceMethodExecution pointcut?

    Any help will be appreciated!


  • #2
    I was not able to reproduce your problem, i.e. aspect method was called only one time.

    Make sure you don't have another aspects that use 'serviceMethodExecution' pointcut.

    You can also create minimal but complete standalone test-case that illustrates the problem and post it here, I'll take a look.


    • #3
      Thanks for your response Denis.

      Sorry I didn't make it clear in the last post, but I do have another aspect that uses serviceMethodExecution. My use case is that I use serviceMethodExecution for defining transactions and logging aspects, but one of the services (ServiceX.someMethod in the example) needs a customized after-advice which I would like to be invoked only once since this after-advice performs some database update operations.

      What's the recommended way to deal with this situation?

      Thanks again!


      • #4
        I'm still unable to reproduce the problem. I.e. I wrote a test-case that uses two aspects that match to particular bean method call. When I create the context, get target bean proxy from it and call target method I observe expected behavior - every aspect's advice method is called once.

        I recommend you to create standalone test-case that illustrates the problem and post it here. That would be much faster than explaining the symptoms.