Spring-boot camel case nested property as environment variable

I have a spring boot application and want to set environment variables to a class annotated with @ConfigurationProperties nested second level property, which is a camel body. Here is an example class:

 @SpringBootApplication @EnableConfigurationProperties(SpringApp.Props.class) @RestController public class SpringApp { private Props props; @ConfigurationProperties("app") public static class Props { private String prop; private Props nestedProps; public String getProp() { return prop; } public void setProp(String prop) { this.prop = prop; } public Props getNestedProps() { return nestedProps; } public void setNestedProps(Props nestedProps) { this.nestedProps = nestedProps; } } @Autowired public void setProps(Props props) { this.props = props; } public static void main(String[] args) { SpringApplication.run(SpringApp.class, args); } @RequestMapping("/") Props getProps() { return props; } } 

when I try to run the application with the following environment variables:

 APP_PROP=val1 APP_NESTED_PROPS_PROP=val2 APP_NESTED_PROPS_NESTED_PROPS_PROP=val3 

I get the following response from the service:

 { "prop": "val1", "nestedProps": { "prop": "val2", "nestedProps": null } } 

Is this the expected behavior? I was expecting something like this:

 { "prop": "val1", "nestedProps": { "prop": "val2", "nestedProps": { "prop": "val3", "nestedProps": null } } } 

When I set properties through application parameters (for example: --app.prop=val1 --app.nestedProps.prop=val2 --app.nestedProps.nestedProps.prop=val3 ), I get the expected response.

Is there any workaround using environment variables and without changing the code to get the expected behavior?

Note. I did some debugging and it looks like the problem arose in org.springframework.boot.bind.RelaxedNames without creating candidates for these cases. Here is the test I did to demonstrate it (it fails):

 @Test public void shouldGenerateRelaxedNameForCamelCaseNestedPropertyFromEnvironmentVariableName() { assertThat(new RelaxedNames("NESTED_NESTED_PROPS_PROP"), hasItem("nested.nestedProps.prop")); } 
+5
source share

All Articles