Skip to content

BeanPostProcessor can eagerly initialize factory beans that use constructor injection #24553

Closed as not planned
@AlesD

Description

@AlesD

Auto configuration of MethodValidationPostProcessor in class org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration requires instance of Environment. Since the envirnonemt does not have @Lazy annotation it triggers autowire candidate resolution with lazyInit=true which in turn results in initialization of (at least) FactoryBeans.

Bean post processors should NOT use autowiring since the beans created just to check that they do not implement Environment are later not eligible for all other bean post processors - which is actually confirmed in log by lots of:

Bean 'xxx' of type [XXX] is not eligible for getting processed by all BeanPostProcessors

I have implemented custom ImportBeanDefinitionRegistrar. When I use it like this:

@SpringBootApplication
@Import(GenesysRegistrar.class)
public class IntegrationServer {
...
}

everything works fine. But if I create my own auto-configuration class:

@Configuration
@Import(GenesysRegistrar.class)
public class GenesysAutoConfiguration {
}

then bean definitions registered by GenesysRegistrar are created BEFORE MethodValidationPostProcessor during search for bean implementing Environment interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions