I am experiencing a weird behaviour when loading external properties to the spring boot (2.0.3.RELEASE
) application using application.yaml
. I will show a minimal example bellow. I have defined a @ConfigurationProperties
class as follows:
@Component
@ConfigurationProperties
class ConfigProperties {
var testString: String = ""
var testMap : MutableMap<String, String> = mutableMapOf()
}
I also have an adequate application.yaml
file:
testString: "/profile/test"
testMap:
"/profile/main" : "Welcome/to/profile"
When evaluated, ConfigProperties.testString
produces /profile/test
as expected but ConfigProperties.testMap
produces a map of size one with the only entry's key set to profilemain
and value set to Welcome/to/profile
. Why does the key ignore a forward slashes (/
) but value is resolved properly? I tried escaping the forward slash but that didn't work. I also found that other special characters like colon (:
) and backslash (\
) also get ignored by the map key.
I know this is old but if someone else is wondering, this is how it works in spring boot 2.
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#relaxed-binding
For map keys with non-alphanumeric characters (other than -) in them, surround the key name with []. For example:
spring:
my-example:
'[foo.baz]': bar
'[abc xyz]': def
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With