Announcement Announcement Module
Collapse
No announcement yet.
Spring AOP apply advice more than once problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring AOP apply advice more than once problem

    Hi there,

    We are having problem with Spring AOP not applying the advice properly. In our live system (on Ubuntu virtual machine) sometimes the aspect applying more than once. (3 times). however in all our development machine it never happens.

    one thing that we notice every time our live system is rebooted, the aspect we have always running 3 times, and then randomly after many tomcat restart it runs back once.

    e.g. of our aspect is when someone posting a message it will create a PDF file of the message
    Code:
    <aop:config>
    		<aop:advisor advice-ref="myPdfAdvice" 
    			pointcut="execution(* com.company.MessageManager.createMessage(..))"/>
    	</aop:config>
    anybody has experience the same one / know how to solve it?

  • #2
    I can't think of any aspect-related reason that can explain the difference between the development and production world. My suggestion is to verify that the MessageManager.createMessage(..) method isn't in fact called multiple times (perhaps just add a log statement to each such method).

    -Ramnivas

    Comment


    • #3
      Using aopointcut and aop:aspect instead

      After testing it few times.. finally I could make it work by replacing with aopointcut and aop:aspect instead of using aop:advisor

      Code:
      <aop:config>
        <aop:pointcut id="createMessagePointcut" 
         expression="execution(* com.company.MessageManager.createMessage(..))"/>
      
        <aop:aspect ref="myPdfAdvice">
           <aop:after-returning method="adviceCreateMessage" 
            arg-names="message" 
            pointcut-ref="createMessagePointcut" /> 
        </aop:aspect>
      
      </aop:config>
      I'm guesssing it was run three times in the production system because I declared the advisor 3 times in different Spring context for different module and somehow after advice it's actually applying the 3 (aop:advisor) x 3 advices instead of running only 3 advices
      Last edited by otnateos; Apr 11th, 2009, 07:03 PM.

      Comment

      Working...
      X