Description
When @EnableConfigurationProperties
is used, corresponding ConfigurationProperties
class is registered as a bean with name <prefix>-<fqcn>
.
This bean name is generated by ConfigurationPropertiesBeanRegistrar#getName
.
This auto-generated name is very inconvenient when the registered bean needs to be referenced by other places such as SpEL.
Current workaround to specify bean name is to use @ConfigurationProperties
with @Bean
instead of @EnableConfigurationProperties
.
@Bean
public MyProperties myProperties() {
return new MyProperties();
}
@ConfigurationProperties("my")
public class MyProperties {
}
If it is declared as a bean, ConfigurationPropertiesBindingPostProcessor
performs binding and the configuration properties bean exists with the bean name via @Bean
.(myProperties
in this example)
I would like to have a capability in @EnableConfigurationProperties
to specify bean name (or may be alias to <prefix>-<fqcn>
) for binding ConfigurationProperties beans.
For example:
@EnableConfigurationProperties(
value = {FooProperties.class, BarProperties.class},
beanNames = {"fooProps", "barProps"})
If this sounds ok, then I'll proceed to create a PR.
Thanks,