Skip to content

AnnotationConfigApplicationContext does not detect BeanFactoryPostProcessor [SPR-6455] #11121

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 Nov 26, 2009 · 2 comments
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 Nov 26, 2009

Dave King opened SPR-6455 and commented

The documentation in several places says:

"Application contexts can auto-detect BeanFactoryPostProcessor beans in their bean definitions and apply them before any other beans get created. "

Thus @Bean BeanFactoryPostProcessor getSomeName(){ return new BeanFactoryPostProcessorImpl();} in a @Configuration class should cause the BeanFactoryPostProcessor run in the AnnotationConfigApplicationContext. Doesn't work. The callback method is never called. The bean is created, but only after other beans have been created.

This breaks the documented contract for an ApplicationContext.


Affects: 3.0 RC2

Reference URL: http://forum.springsource.org/showthread.php?t=81044

Issue Links:

Referenced from: commits 6b2b5c4, 8ab9da4

3 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

Grzegorz Grzybek commented

Also there is problem with BeanFactoryPostprocessors registered in XML context included using @ImportResource annotation.
The problem is with an example in 3.11.3.2 chapter of reference doc:

@Configuration
@ImportResource("classpath:/com/acme/properties-config.xml")
public class AppConfig {
    private @Value("${jdbcProperties.url}") String url;
    private @Value("${jdbcProperties.username}") String username;
    private @Value("${jdbcProperties.password}") String password;

    public @Bean DataSource dataSource() {
        return new DriverManagerDataSource(url, username, password);
    }
}

does not work @ImportResource is processed by last call to {invokeBeanFactoryPostProcessors} in {org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory)}, so to invoke bean factory postprocessors defined in XML included with @ImportResource, there is a need for one more {invokeBeanFactoryPostProcessors} call..

does this loop ever ends?

regards
Grzegorz Grzybek

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Fixed through introducing a BeanDefinitionRegistryPostProcessor which gets invoked against the BeanDefinitionRegistry - before BeanFactoryPostProcessors get retrieved and applied. Any bean definitions registered by a BeanDefinitionRegistryPostProcessor are eligible for being run as BeanFactoryPostProcessors in the next phase. ConfigurationClassPostProcessors takes advantage of exactly that benefit, processing @Bean method in the BeanDefinitionRegistryPostProcessor phase now.

Juergen

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