Description
I use the configuration properties feature to bind properties multiple times using different prefixes which are dynamic in nature.
@ConfigurationProperties(prefix = "client-a")
@Bean
public MyClientProperties clientAproperties() {
return new MyClientProperties();
}
@ConfigurationProperties(prefix = "client-b")
@Bean
public MyClientProperties clientBproperties() {
return new MyClientProperties();
}
As long as the MyClientProperties
class is local to my spring-boot project, the spring-boot-configuration-processor
is able to generate metadata for each prefix I use. In particular, the description
and defaultValue
metatdata is extracted from the field level javadoc of the class:
public class MyClientProperties {
/**
* Web service remote endpoint url
*/
public String endpoint = "http://localhost:8080/services";
...
}
The generated metadata
{
"name": "client-a.endpoint",
"type": "java.lang.String",
"description": "Web service remote endpoint url",
"sourceType": "com.example.client.MyClientProperties",
"defaultValue": "http:\/\/localhost:8080\/services"
},
...
{
"name": "client-b.endpoint",
"type": "java.lang.String",
"description": "Web service remote endpoint url",
"sourceType": "com.example.client.MyClientProperties",
"defaultValue": "http:\/\/localhost:8080\/services"
},
This changes as soon as the class is moved to an external jar dependency in order to be shared among several projects and the spring-boot-configuration-processor
has no access to the source code of the properties type. The description
and defaultValue
metadata is no longer available.
{
"name": "client-a.endpoint",
"type": "java.lang.String",
"sourceType": "com.example.client.MyClientProperties"
},
...
{
"name": "client-b.endpoint",
"type": "java.lang.String",
"sourceType": "com.example.client.MyClientProperties"
},
If MyClientProperties
would be used with a fixed prefix only, I could run the spring-boot-configuration-processor
within the external jar module and package the generated metatdata.json file. The generated metadata would be visible in the context of the consuming spring-boot application under the my-client
prefix.
@@ConfigurationProperties(prefix = "my-client")
public class MyClientProperties {
...
}
What I need is a mechanism to access the description
and defaultValue
metatdata from the externally provided properties class below the dynamic prefixes chosen by the consuming spring-boot application.
Note: I submited a question at StackOverflow, but in the meantime I think this is most likely an enhancement request.