- Spring 5.3.3
- Spring Boot 2.4.2
- AspectJ 1.9.6
We use AspectJ compile Time Weaving to manage @Transactional annotations. Everything works fine until we activate spring.main.lazy-initialization=true. The Transaction is not started.
The error is somewhere in TransactionAspectSupport, as the beanFactory is still null when running with lazy-init activated:
protected TransactionManager determineTransactionManager(@Nullable TransactionAttribute txAttr) {
// Do not attempt to lookup tx manager if no tx attributes are set
if (txAttr == null || this.beanFactory == null) {
return getTransactionManager();
}
I hope this is a spring issue and not a Spring Boot issue. I searched the docs if lazy-init is not supported with AspectJ but I did not found anything and didn't any other issue regarding this bug.
Very small project reproducing the issue: https://github.com/kicktipp/spring-lazy-aspectj-issue
Just checkout and run
./gradlew test --tests NonLazyTest
./gradlew test --tests LazyTest
First on with success, second one fails.
If you need further information I am eager to help.
Comment From: snicoll
Thanks very much for the sample, and sorry it took so long to process it. I can confirm the issue, but this shouldn't be addressed in the core framework so I am going to move this issue to the Spring Boot issue tracker.
I've updated your sample to a supported Spring Boot version, and added a way to opt-out explicitly from Lazy processing of TransactionAspectSupport. This made your sample pass this way.
See https://github.com/snicoll-scratches/spring-lazy-aspectj-issue