Skip to content

Self-injection in configuration class hierarchies broken [SPR-10668] #15296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jun 19, 2013 · 1 comment
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 19, 2013

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:

  1. Clone the repo:
  2. Run mvn clean test -> works
  3. Upgrade Spring version in the pom.xml to 4.0.0.BUILD-SNAPSHOT
  4. Run mvn clean test -> fails

Issue Links:

Referenced from: commits a403e8f

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

Hi Oliver,

Thanks for the excellent analysis, it helped a lot.

I have committed a fix that resolves the test case but I would appreciate it if you could double check the latest snapshot against DATAGRAPH-363.

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants