Closed neshkeev closed 2 months ago
Software Developers often combine a bunch of technologies in a single application with results in several @ConfigurationProperties Spring Beans one for each in use technologies.
That's the expected behavior as the scope of these are quite different, even in the scope of an application.
AFAIK flagging the four fields in MyAppProperties
with @NestedConfigurationProperty
should do pretty much that, except the repetition of the prefix, so something like myapp.first-datasource.name
instead of myapp.first-datasource.spring.datasource.name
.
I don't really understand why you'd want the prefix to be repeated.
If @ConfigurationProperties
beans are embeddable then I can reuse the @ConfigurationProperties
classes from Spring Boot to compose my app's own @ConfigurationProperties
bean with an arbitrary structure that suits my needs the most.
flagging the four fields in MyAppProperties with @NestedConfigurationProperty should do pretty much that
Using NestedConfigurationProperty
can do the trick, but at the same time I lose all the auto-configuration abilities. So in addition to getting a custom @ConfigurationProperties
bean that might consist of Spring Boot's own @ConfigurationProperties
beans I also would like to keep automatic configuration of Datasources, JMS connections and so on.
It would be nice for Spring Boot to handle the following case:
@ConfigurationProperties
bean is nested inside another @ConfigurationProperties
bean@ConfigurationProperty
Spring bean for the former bean is createdThanks, it was far from obvious to me that you expected auto-configuration to apply to those. I think the embedded bits is by far a detail compared to having auto-configuration deal with multiple beans of the same type.
I am going to close this in favor of #15732 where that feature is discussed at length.
Motivation
ConfigurationProperties
has many of out-of-box implementations for different technologies, like Apache Kafka, DataSource, JMS, etc.Software Developers often combine a bunch of technologies in a single application with results in several
@ConfigurationProperties
Spring Beans one for each in use technologies.Proposal
It would be great to have a way to combine all the
@ConfigurationProperties
beans in a single@ConfigurationProperties
Spring Bean and keep all the auto-configuration abilities at the same timeExample
There is an
application.properties
file with two Apache Kafka Clusters and two Data Sources:It would be nice to be able to define a bean that reads all the properties into a single bean like this:
So then I can inject this single bean instead of a bunch of
@ConfigurationProperties
beans:Alternatives
It's possible to manually construct such an bean like:
The class for the app's properties:
A
@Configuration
bean that construct a bean for the app's properties: