You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
When I use spring-boot to create an object that supports transactions, the object can not be correctly created #9416
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 .
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.
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 [/+]on 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.
Activity
wilkinsona commentedon Jun 6, 2017
Your
BootApplicationis providing a customjavax.validation.Validator. ThisValidatorbean is used by Spring Boot'sValidationAutoConfigurationto create aMethodValidationPostProcessor. This is aBeanPostProcessorso it is created as early as possible to allow it to post-process as many beans as possible. You are injectingFooServiceintoBootApplication. This injection must be done before any of its bean methods can be called, i.e. before itsmyValidator()method can be called to allow the container to create theMethodValidationPostProcessor. As a result, aFooServiceinstance is being created before all of the context's bean post-processors have been set up. As a result you see these log messages: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
Validatorlazily inValidationAutoConfiguration.wilkinsona commentedon Jun 6, 2017
Injecting a
@LazyValidatorhas revealed a bug in Spring Framework: SPR-15629.[-]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 [/+]lanmolsz commentedon 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.
philwebb commentedon 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 commentedon Jul 7, 2017
@philwebb We need to add
@Lazyto the injection of theValidatorinValidationAutoConfigurationStop auto-config of MethodValidationPP triggering early init
Revert "Stop auto-config of MethodValidationPP triggering early init"
wilkinsona commentedon Jul 21, 2017
Unfortunately, the underlying Framework problem's still there. I've opened SPR-15807.
Stop auto-config of MethodValidationPP triggering early init