Oliver Drotbohm opened SPR-10668 and commented
Assume you have a configuration class autowiring a component a subclass of this config class might declare:
@Configuration
class ParentConfig {
@Autowired(required = false) MyComponent component;
}
@Configuration
class ChildConfig extends ParentConfig {
@Bean
public MyComponentImpl myComponent() { … }
}
This fails with a rather ambiguous:
Caused by: java.lang.IllegalArgumentException: Object of class [null] must be an instance of interface org.springframework.beans.factory.config.ConfigurableBeanFactory
at org.springframework.util.Assert.isInstanceOf(Assert.java:339)
at org.springframework.util.Assert.isInstanceOf(Assert.java:319)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.getBeanFactory(ConfigurationClassEnhancer.java:414)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:289)
at de.olivergierke.samples.spring.ConfigClassExtensionTest$ChildConfig$$EnhancerByCGLIB$$769c39d2.myComponent(<generated>)
This seems to be caused by the fix for #14941. Previously a BeanFactory instance had been available at the point in time when the autowiring happens. As of the change, the BeanFactory will be injected through an BeanFactoryAware call which by Spring's lifecycle happens after property injection. Thus the required BeanFactory is null when the injection shall happen and thus it fails.
I have an executable sample for this at http://github.com/olivergierke/spring-samples. Steps to reproduce:
- Clone the repo:
- Run
mvn clean test -> works
- Upgrade Spring version in the
pom.xml to 4.0.0.BUILD-SNAPSHOT
- Run
mvn clean test -> fails
Issue Links:
Referenced from: commits a403e8f
Oliver Drotbohm opened SPR-10668 and commented
Assume you have a configuration class autowiring a component a subclass of this config class might declare:
This fails with a rather ambiguous:
This seems to be caused by the fix for #14941. Previously a
BeanFactoryinstance had been available at the point in time when the autowiring happens. As of the change, theBeanFactorywill be injected through anBeanFactoryAwarecall which by Spring's lifecycle happens after property injection. Thus the requiredBeanFactoryisnullwhen the injection shall happen and thus it fails.I have an executable sample for this at http://github.com/olivergierke/spring-samples. Steps to reproduce:
mvn clean test-> workspom.xmlto 4.0.0.BUILD-SNAPSHOTmvn clean test-> failsIssue Links:
Referenced from: commits a403e8f