سؤال

I'm pretty confused by this topic and see very little advice in the Spring 4.x documentation. First off let me state that I can configure my project any way I want. Static weaving, compile time weaving, none, etc.

I just want the optimal performance. But if the performance differences are microseconds then I just want simplest. I only care about a performance difference that would impact my customers.

Okay, so here are the relevant options:

  1. adviceMode=proxy, proxyTargetClass=true
  2. adviceMode=proxy, proxyTargetClass=false
  3. adviceMode=aspectJ, compile-time weaving
  4. adviceMode=aspectJ, load-time weaving

I'm okay with adding some time to my application initialization as long as it is fast while running.

So what are the trade offs between these four ways of configuring transaction management?

Are there feature trade-offs too or is this just a performance issue?

Note that I am using Spring 4.0.2 and Java 1.7. If there is Spring 4.0 documentation that basically answers this question then I apologize and just redirect me to the doc. So far I've seen documentation saying how to set them up but not how they compare. Thanks!

Also note that most of the information on the web about this is really out of date. So I'm looking for current comparisons.

هل كانت مفيدة؟

المحلول

This configuration says how the transaction aspect will be applied. Briefly:

adviceMode=proxy, proxyTargetClass=true Cglib is used as proxy mechanism. If you use this, cglib must be on classpath, your proxied classes must have nonparametric constructor and they can't be final (cglib creates a child class as the proxy).

adviceMode=proxy, proxyTargetClass=false Jdk proxy mechanism is used. You only can proxy classes that implements a interface for methods that should be transactional. Jdk proxy can be type casted to the interfaces but can't be type casted as the original proxied class.

So, for adviceMode=proxy, the decision relies more on how are your code standards and what constraints result from used proxy mechanism.

adviceMode=aspectJ uses aspectJ library, which does byte code intrumentation instead of proxying.

adviceMode=aspectJ, compile-time weaving You should incorporate aspectJ instrumentation during a build process in your build scripts.

adviceMode=aspectJ, load-time weaving Instrumentation is performed on runtime. You have to put the aspectj agent as jvm parameter.

Using aspectJ is more powerful and probably more performant. It is also less invasive in terms of restrictions put on the classes you want to be transactional. However, proxy mode is simple Spring's out of the box solution.

More on proxies here http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch08s06.html. More on aspectJ with spring here http://docs.spring.io/spring/docs/3.0.0.M4/reference/html/ch07s08.html.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top