Skip to content

When I use spring-boot to create an object that supports transactions, the object can not be correctly created #9416

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
lanmolsz opened this issue Jun 6, 2017 · 6 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@lanmolsz
Copy link

lanmolsz commented Jun 6, 2017

https://github.com/lanmolsz/spring-boot-bugs
this github address can reproduce the problem

the FooService object injected into BootApplication is a plain object, not an supports transactions proxy object.

When I commented myValidator method or testInject method,FooService object is correct.

To confirm this bug comes from spring boot , I added BasicApplication class, It is a normal spring application. In BasicApplication , It will correct running.

I’m sorry, my English not so good , I hope you can understand the above words .

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 6, 2017
@wilkinsona wilkinsona self-assigned this Jun 6, 2017
@wilkinsona
Copy link
Member

wilkinsona commented Jun 6, 2017

Your BootApplication is providing a custom javax.validation.Validator. This Validator bean is used by Spring Boot's ValidationAutoConfiguration to create a MethodValidationPostProcessor. This is a BeanPostProcessor so it is created as early as possible to allow it to post-process as many beans as possible. You are injecting FooService into BootApplication. This injection must be done before any of its bean methods can be called, i.e. before its myValidator() method can be called to allow the container to create the MethodValidationPostProcessor. As a result, a FooService instance is being created before all of the context's bean post-processors have been set up. As a result you see these log messages:

2017-06-06 16:21:35.183  INFO 22103 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'fooServiceImpl' of type [com.jikezhiji.examples.FooServiceImpl] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
…
2017-06-06 16:21:35.184  INFO 22103 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'bootApplication' of type [com.jikezhiji.examples.BootApplication$$EnhancerBySpringCGLIB$$7b11250] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2017-06-06 16:21:35.244  INFO 22103 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'myValidator' of type [org.springframework.validation.beanvalidation.CustomValidatorBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

You can avoid the problem by not injecting any dependencies into the configuration class that's producing the custom validator.

We could possibly help you to avoid the problem by consuming the Validator lazily in ValidationAutoConfiguration.

@wilkinsona
Copy link
Member

Injecting a @Lazy Validator has revealed a bug in Spring Framework: SPR-15629.

@wilkinsona wilkinsona added priority: normal type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 6, 2017
@lanmolsz lanmolsz changed the title When I use spring-boot to create an object that supports transactions, the object can not be created correctly When I use spring-boot to create an object that supports transactions, the object can not be correctly created Jun 7, 2017
@lanmolsz
Copy link
Author

lanmolsz commented Jun 7, 2017

@wilkinsona In the process of reproducing this problem, I found that some changes in the code will trigger this problem, I can bypass it to avoid triggering the problem. However, you have solved my question, thank you.

@wilkinsona wilkinsona added this to the 1.5.5 milestone Jun 12, 2017
@philwebb
Copy link
Member

philwebb commented Jul 6, 2017

@wilkinsona Can I close this one now that SPR-15629 is fixed, or is there something else on our end to do?

@wilkinsona
Copy link
Member

@philwebb We need to add @Lazy to the injection of the Validator in ValidationAutoConfiguration

@wilkinsona wilkinsona reopened this Jul 21, 2017
wilkinsona added a commit that referenced this issue Jul 21, 2017
5198fe8. The underlying Framework
problem that prevents @lazy from working properly is still there
in some form or another.

See gh-9416
@wilkinsona
Copy link
Member

Unfortunately, the underlying Framework problem's still there. I've opened SPR-15807.

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