Spring annotation-based vs xml-based transaction definitions precedence

I couldn’t find a definitive answer to this in the docs, and although there seems to be a logical answer, one can’t be sure. The scenario is this – you have a xml-based transaction definition, like:

<tx:advice id="txAdvice" transaction-manager="jpaTransactionManager">
        <tx:method name="*" propagation="REQUIRED" />

Which advises all service methods. But then you have @Transactional on a concrete class/method, where you want to override the propagation attribute.

It is clear that @Transactional at method-level overrides the same one at class-level, but does it override the <tx:advice> (and actually, the <aop:pointcut>)?

It turns out the behaviour is less than expected:

  1. Both <aop:advisor> and @Transactional (together with <tx:annotation-driven>) create a TransactionInterceptor around the target class (the one, whose methods are to be run in transaction).
  2. The advice with a lower order attribute overrides the other one. If no order attribute is specified, the order is undefined. But my tests showed that the one defined latest in the applicationContext.xml takes precedence, although this might not be the case always:

    When two pieces of advice defined in different aspects both need to run at the same join point, unless you specify otherwise the order of execution is undefined.

This is the behaviour for spring 2.5.6. Spring 3.0 might have redefined this.


One Response to “Spring annotation-based vs xml-based transaction definitions precedence”

  1. Soila Rousu Says:

    Today, I am quite excited…. and a little anxious. The reason for this is that I just quit my job of 20 years. This was not an easy decision to make because I have a large family to support. Why did I do this? Awhile back I started this online business reselling a certain software. What got me started in it was the fact that it just looked so promising. In the back of my mind I thought that it was probably too good to be true but in the end, as you can see by the fact that I have now quit my job, I feel that it was more like a life changing event. When I first started, I was promised all the help that I would need, and that’s exactly what I got. Let me just tell you what this is about so that you can get in on it too. The software itself is a lead extraction and broadcasting system. What does that mean? Basically, it goes out to places like Google, Merchant Circle, Craigslist and other popular web spaces and then it gathers targeted leads for you. After the leads are gathered, you can then use the software to ‘broadcast’ your message, whatever that may be, to these new targeted prospects. It uses direct email and phone broadcasting to do this. It is very attractive to people in certain industries and that makes the software easy to sell. Here’s where the magic starts though. They use the 1-Up compensation plan for selling this software. This means that you could make an infitite amount of money from each sale. There are people who have tweeked the way that they market this system so that they are making over $100,000 per month. There are many more who are making 5 figures per month with this program. The main key to getting started with this is to sign up with the right downline. You need to sign up with the Cash411 downline. They offer a combined bonus that is valued at thousands of dollars (You really need to see what they offer). It is in there best interest to make sure that you do well with the system and so they are offering dozens of free marketing tools, mentoring and tutorials to help you get started. You won’t have to just rely on the software itself. You will be able to use all the other tools so that you can get off to a fast and successful start. Getting in on this deal is really a no-brainer. Go check it out for yourself. -> http://cash411.info/gopro

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: