When using @ConfigurationProperties, the camelCase variable names are resolved correctly from environment variables when they contain an _ character between the camelcase parts.
Version
The issue was discovered on 2.1.5, but also confirmed on 2.4.3.
Details
Given an app with a configuration property props.confValue in the application.yml, if users try to use an the environment value PROPS_CONF_VALUE they resolve to different values if they use @ConfigurationProperties compared to using @Value("props.confValue").
application.yml
props:
confValue: defaultValue
Using @ConfigurationProperties
@ConfigurationProperties("props")
class ConfigProps {
var confValue: String? = null
}
Using @Value
@Component
class AutowiredValueBean() {
@Value("\${props.confValue}")
lateinit var confValue: String
}
Test cases:
Starting the app with PROPS_CONF_VALUE=envValue results in
- ConfigProps.confValue having the value of envValue
- AutowiredValueBean.confValue having the value of defaultValue
Starting the app with PROPS_CONFVALUE=envValue results in
- ConfigProps.confValue having the value of envValue
- AutowiredValueBean.confValue having the value of envValue
A reproduction of the issue can be found here.
Comment From: snicoll
Thanks for the sample.
There's a note in the reference guide about this. Rather than using props.confValue you should be using props.conf-value so that the same rules apply.