Synopsis of the original question: Using standard Spring Transactions with AOP proxying, it is not possible to call an @Transactional-marked method from a n
By reading your question it's not really clear where you are stuck, so I am going to briefly list what is needed to get AspectJ intercept your @Transactional
methods.
@Transactional
annotation: <aspect name="org.springframework.transaction.aspectj.AnnotationTransactionAspect"/>
<include within="foo.*"/>
aspectjrt.jar
, aspectjweaver.jar
, spring-aspects.jar
and spring-aop.jar
in the classpath-javaagent:/path/to/spring-instrument.jar
(or spring-agent, as it is called in earlier releases)The final step may not be necessary. It is a really simple class that enables using the InstrumentationLoadTimeWeaver
, but if not available Spring will try to use another load time weaver. I have never tried that, though.
Now, if you think you have fulfilled all steps and still are having problems, I can recommend enabling some options on the weaver (defined in aop.xml):
<weaver options="-XnoInline -Xreweavable -verbose -debug -showWeaveInfo">
This makes the weaver output a bunch of information what is being weaved. If you see classes being weaved, you can look for your TestClass
there. Then you at least have a starting point to continue troubleshooting.
Regarding your second edit, "It's almost like the weaving isn't happening fast enough to be woven before the class tries to execute.", the answer is yes, this can happen. I experienced a situation like this before.
I am a little rusty on the specifics, but basically it is something in the lines that Spring will not be able to weave classes that are loaded before the application context is being created. How are you creating your application context? If you are doing it programatically, and that class has a direct reference to TestClass
, then this problem could occur, since TestClass
will be loaded too early.
Unfortunately, I have found that debugging AspectJ is hell.