Announcement Announcement Module
Collapse
No announcement yet.
AOP Advice Ordering & Declarative Transaction Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AOP Advice Ordering & Declarative Transaction

    Hi,

    I am using Spring/Hibernate with declarative transaction:

    <aop:config>
    <aop:advisor id="managerTx" advice-ref="txAdvice"
    pointcut="execution(* *..service.*Manager.*(..))" order="2" />
    </aop:config>

    <tx:advice id="txAdvice">
    <tx:attributes>
    <tx:method name="get*" read-only="true" />
    <tx:method name="*" />
    </tx:attributes>
    </tx:advice>


    Now I want to add an after-returning advice on a method foo() of one of my Managers. Say,

    CustomerManager.foo(..)

    foo(..) will do insert one record in DB.

    I want to make sure that the transaction has been commited before my advice take control. So I added the following annotations in my advice method

    @AfterReturning(execution("* CustomerManager.foo(..)"))
    @Order(5)
    public void myAdvice(){
    .......
    }

    However, the @Order annotation dos not seem to work. myAdvice() is called when foo() is called. But on exit, it is called before transaction is commited.

    My undertsanding is that Spring uses AOP implement transactin management - I just don't know why my Order annotation (value "10") does not work as I expected.
    The tx advice order is only "2".

    Any idea?

    Thanks.

    Joe

  • #2
    Solved:

    Given two aspects, the aspect returning the lower value from Ordered.getValue() (or the annotation value) has the higher precedence.

    So Ordered.getValue() should return a lower value.

    Comment


    • #3
      AOP advice ordering

      Please go through the following blog, if anyone want to know more about spring aop advice ordering:

      http://java-sample-program.blogspot....-ordering.html

      Comment

      Working...
      X