Doc: @Transactional on private methods with aspectj mode [SPR-13843] #18416
Comments
Juergen Hoeller commented How does your account mapper bean work? Have you double-checked that it actually participates in such transactions? That aside, have you verified that the AspectJ transaction aspect is actually weaved in, either through compile-time weaving or through load-time weaving? Otherwise your You could check Juergen |
Xiaolong Zuo commented I find the AspectJ transaction aspect is not actually weaved in, and the method TransactionSynchronizationManager.isActualTransactionActive() return false within all the out and inner method. |
Xiaolong Zuo commented Maybe I lost some configuration? |
Xiaolong Zuo commented But I don't find additional configuration in the docs. |
Juergen Hoeller commented For load-time weaving, you'll need a context:load-time-weaver element in your configuration, and a corresponding class loader underneath (e.g. through specifying the spring-instrument agent using a -javaagent command line argument for your JVM). This is unfortunately a rather advanced configuration arrangement and not as trivial to set up as proxy-based interception. Let's turn this into a documentation issue. I'll see what we can do for 4.3 there. Juergen |
Xiaolong Zuo commented I'm so sorry, what I just said is not right. public void out() {
UsAccount usAccount1 = new UsAccount();
usAccount1.setId(1);
usAccount1.setType((byte) 1);
System.out.println(TransactionSynchronizationManager.isActualTransactionActive());
usAccountMapper.updateByPrimaryKeySelective(usAccount1);
inner();
} private void inner() {
System.out.println(TransactionSynchronizationManager.isActualTransactionActive());
UsAccount usAccount2 = new UsAccount();
usAccount2.setId(3);
usAccount2.setType((byte) 1);
usAccountMapper.updateByPrimaryKeySelective(usAccount2);
throw new RuntimeException();
} The conditions above show that only use proxy mode and add |
Xiaolong Zuo commented I think the weave way is CTW usually. |
Juergen Hoeller commented Compile-time weaving is certainly more reliable. However, it requires special build setup: compiling your application code with |
Xiaolong Zuo commented Does CTW need to use AspectJ compiler? |
Xiaolong Zuo commented I got it.Thanks very much.I try to use LTW,but get excepetion below. |
Xiaolong Zuo commented The web container what I use is tomcat . When I change weaver-class to TomcatLoadTimeWeaver,then get exception below. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.weaving.AspectJWeavingEnabler#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Could not initialize TomcatLoadTimeWeaver because Tomcat API classes are not available |
Juergen Hoeller commented Which version of Tomcat are you using? Recent versions of Tomcat 7 and 8 should provide that Juergen |
Xiaolong Zuo commented Thanks,Juergen. |
Xiaolong Zuo opened SPR-13843 and commented
I would like to use
@Transactional
to private method.I find a way from springdocs 16.5.9,but it's unavailable.My spring config file like below:
My service class like below:
I expect the usAccount1's type is 1 and the usAccount2's type is 0(original value in db is 0),but all the two usAccount's type are 1.
Affects: 4.1.7
Backported to: 4.2.7
The text was updated successfully, but these errors were encountered: