Skip to content

Allow specifying beanname on @EnableConfigurationProperties #19390

Closed
@ttddyy

Description

@ttddyy

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions