Skip to content
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

Factory Bean, BeanDefinitionRegistryPostProcessor and XML config causes properties to not be available #33522

Open
grahamcox-oclc opened this issue Sep 10, 2024 · 0 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on

Comments

@grahamcox-oclc
Copy link

grahamcox-oclc commented Sep 10, 2024

Affects: 5.3.29, 6.1.12, probably others. I've not done an exhaustive search.


We've hit a problem with using factory beans that are constructed from XML configuration and have properties injected into them, when there is a BeanDefinitionRegistryPostProcessor calling BeanFactoryUtils.beanNamesForTypeIncludingAncestors in the postProcessBeanDefinitionRegistry method.

This sounds very specific - and it is - but this has come about because the OAuth2ClientConfiguration class from spring-security-config does exactly this. (Note that this didn't happen with this OAuth2ClientConfiguration class in Spring 5 but does in Spring 6. However, the bug as a whole reproduces in Spring 5 when I do it myself)

From what we can tell, when this setup exists the factory bean is instantiated before the properties are loaded, and therefore the wrong value is provided.

Things we've also noticed:

  • This only happens when the factory bean is constructed from XML config. If it's component scanned, or constructed from Java config then it works correctly. This includes if the Java config is itself loaded because it was referenced in XML config.
  • This reproduces whether the factory bean extends AbstractFactoryBean or implements FactoryBean.
  • I've managed to reproduce it in a Spring Boot app from https://start.spring.io, but we first noticed it in a Spring MVC app.

I've attached a Minimal reproducible example to show this happening.
properties.zip

Cheers

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 10, 2024
@bclozel bclozel added the in: core Issues in core modules (aop, beans, core, context, expression) label Sep 10, 2024
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) status: waiting-for-triage An issue we've not yet triaged or decided on
Projects
None yet
Development

No branches or pull requests

3 participants