Skip to content

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

Closed

Description

@lanmolsz

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 .

Activity

  1. added
    status: waiting-for-triage
    on Jun 6, 2017
  2. self-assigned this
    on Jun 6, 2017
  3. wilkinsona commented on Jun 6, 2017

    @wilkinsona
    Member

    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.

  4. wilkinsona commented on Jun 6, 2017

    @wilkinsona
    Member

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

  5. added
    type: bug
    and removed
    status: waiting-for-triage
    on Jun 6, 2017
  6. 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
  7. lanmolsz commented on Jun 7, 2017

    @lanmolsz
    Author

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

  8. added this to the 1.5.5 milestone on Jun 12, 2017
  9. philwebb commented on Jul 6, 2017

    @philwebb
    Member

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

  10. wilkinsona commented on Jul 7, 2017

    @wilkinsona
    Member

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

  11. added a commit that references this issue on Jul 21, 2017
    5198fe8
  12. wilkinsona commented on Jul 21, 2017

    @wilkinsona
    Member

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

  13. added
    status: blocked
    on Jul 21, 2017
  14. modified the milestones: 1.5.6, 1.5.5 on Jul 21, 2017
  15. removed
    status: blocked
    on Oct 1, 2018
  16. added a commit that references this issue on Feb 8, 2026
    5938df5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions