-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Allow specifying beanname on @EnableConfigurationProperties #19390
Comments
I'm not sure we want to go there. Configuration properties classes are public API by nature, but they're much more likely to change than the rest (because they tend to follow closely changes in 3rd party libraries). |
Hi, @bclozel Just for FYI, my usage is to reference to our own properties. (not 3rd party) Something like this: my:
schedule:
delay: 30s @Scheduled(
initialDelay = "#{@myProperties.getSchedule().getDelay().toMillis() + " +
"T(java.util.concurrent.ThreadLocalRandom).current().nextInt(3*60*1000)}") Here, |
We discussed this as a team today and we aren't convinced that using a second array in the One other thing to consider is not trying to use SpEL for this type of configuration. It can be quite brittle as it doesn't fail until runtime. I believe that Spring offers programmatic support for scheduling beans via the |
ok, thanks @philwebb I think it would be useful if there is some documentation about this as a guideline or best practice. Something like "Referencing @ConfigurationProperties as a bean in SpEL"
|
Unfortunately, this tends to make people use |
When
@EnableConfigurationProperties
is used, correspondingConfigurationProperties
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
.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:
If this sounds ok, then I'll proceed to create a PR.
Thanks,
The text was updated successfully, but these errors were encountered: