-
Sep 12th, 2007, 09:08 PM
#1
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
-
Sep 12th, 2007, 09:41 PM
#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.
-
Nov 18th, 2012, 02:43 AM
#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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules