-
Notifications
You must be signed in to change notification settings - Fork 41.2k
@ConfigurationPropertiesBinding should be @Role(BeanDefinition.ROLE_INFRASTRUCTURE) #45622
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
Comments
We discussed this today and decided that the recommendation to use |
I am not sure that the @ExtendWith(OutputCaptureExtension.class)
class ConfigurationPropertiesBindingTests {
@Test
void infracheck(CapturedOutput capturedOutput) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(InfraBeanPostProcessorConfiguration.class, InfraConfig.class);
context.refresh();
context.close();
assertThat(capturedOutput.getAll()).doesNotContain("is not eligible for getting processed");
}
@ConfigurationProperties("infra")
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
static class InfraProperties {
}
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(InfraProperties.class)
static class InfraConfig {
@Bean
@ConfigurationPropertiesBinding
static Converter<Object, Object> infraConverter() {
return (source) -> source;
}
}
@Configuration(proxyBeanMethods = false)
static class InfraBeanPostProcessorConfiguration {
@Bean
static InfraBeanPostProcessor infraBeanPostProcessor(InfraProperties infraProperties) {
return new InfraBeanPostProcessor();
}
}
static class InfraBeanPostProcessor implements BeanPostProcessor {
}
} When |
Yes, that's right. However, our opinion is that the better fix is not to inject dependencies into a method that defines a |
I understand this, but since If, for some reason, someone tries to do the same in the future, they will probably face the same issue because of a similar cause, and users can't change |
Uh oh!
There was an error while loading. Please reload this page.
Any bean that is
@ConfigurationPropertiesBinding
will be created during bean post-processing for configuration property binding. As such, it may not be eligible for full post-processing which will result in a warning being logged. The warning will be something like this:As the warning suggests, it can be avoided by declaring the bean in the infrastructure role (as well as declaring the bean method
static
(#45621)). I think we should meta-annotate@ConfigurationPropertiesBinding
with@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
but I'd like to discuss this with the team to make sure I haven't overlooked anything and to agree upon the branches that will have the fix applied.The text was updated successfully, but these errors were encountered: