Results 1 to 3 of 3

Thread: AOP Advice Ordering & Declarative Transaction

  1. #1

    Default 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. #2

    Default

    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.

  3. #3
    Join Date
    Nov 2012
    Posts
    6

    Default 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

Posting Permissions

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