Skip to content

AspectJ transaction management with compile-time weaving does not work with spring.main.lazy-initialization=true #37506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kicktipp opened this issue Feb 9, 2021 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@kicktipp
Copy link

kicktipp commented Feb 9, 2021

  • 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.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 9, 2021
@sbrannen sbrannen changed the title AspectJ Transactional Management and spring.main.lazy-initialization=true AspectJ transaction management and spring.main.lazy-initialization=true Feb 9, 2021
@snicoll snicoll self-assigned this Sep 21, 2023
@snicoll
Copy link
Member

snicoll commented Sep 21, 2023

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

@snicoll snicoll transferred this issue from spring-projects/spring-framework Sep 21, 2023
@snicoll snicoll removed their assignment Sep 21, 2023
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 29, 2023
@wilkinsona wilkinsona added this to the 2.7.x milestone Sep 29, 2023
@wilkinsona wilkinsona changed the title AspectJ transaction management and spring.main.lazy-initialization=true AspectJ transaction management with compile-time weaving does not work with spring.main.lazy-initialization=true Sep 29, 2023
@wilkinsona wilkinsona self-assigned this Sep 29, 2023
@wilkinsona wilkinsona modified the milestones: 2.7.x, 2.7.17 Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants