Spring Boot 2.4.2

Using two beans: Parent implements InitializingBean and @Configurable Child. Parent inside afterPropertiesSet creates a Child instance.

The newly created child doesn't have any @Autowired props set because BeanConfigurerSuport is not initialized (null beanfactory): https://github.com/spring-projects/spring-framework/blob/8589804012efda8db2d70094e8efbd8f74d06dc5/spring-beans/src/main/java/org/springframework/beans/factory/wiring/BeanConfigurerSupport.java#L126-L133

This happens during spring boot startup, stacktrace:

....
preInstantiateSingletons:897, DefaultListableBeanFactory (org.springframework.beans.factory.support)
finishBeanFactoryInitialization:879, AbstractApplicationContext (org.springframework.context.support)
refresh:551, AbstractApplicationContext (org.springframework.context.support)
refresh:143, ServletWebServerApplicationContext (org.springframework.boot.web.servlet.context)
refresh:758, SpringApplication (org.springframework.boot)
refresh:750, SpringApplication (org.springframework.boot)
refreshContext:397, SpringApplication (org.springframework.boot)
run:315, SpringApplication (org.springframework.boot)

The BeanConfigurerSuport is initialized (setBeanFactory) when org.springframework.context.config.internalBeanConfigurerAspect is created. During initialization, org.springframework.context.config.internalBeanConfigurerAspect has index 174 inside beanNames list: https://github.com/spring-projects/spring-framework/blob/8589804012efda8db2d70094e8efbd8f74d06dc5/spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java#L921 This means, all 173 beans created before cannot use @Configurable (this includes some of my user beans).

This bean should be initialized with priority, before any user bean, so that @Configurable will work.

Comment From: esimioni

I have a different scenario, but probably with the same root cause. I've been using AspectJ and @Configurable for 10 years in a project without issues.

Recently I have tried to use the config option spring: main: lazy-initialization: true and everything works fine, except for the @Configurable beans, which don't have their dependencies injected.

Comment From: snicoll

I have a hard time understanding what this is doing (especially the part where a bean instance is created in afterPropertiesSet). To provide further support, please share a small sample that we can run ourselves.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.