Skip to content

Set environment property in yaml using placeholder

I have a map propMap, set as a PropertySource in the Environment object in my Spring Boot application. What would be the correct notation to access a key in the map from the .yaml file?

I tried using username: "#{propMap.['username']}" but doesn’t seem to work. I tried few others too but didn’t help. Could I know what would be the correct expression I could use in this case?

Thank you


When you add a map property source to the environment, every key-value pair in the map becomes a property in the environment. The property’s name is the key from the map and the property‚Äôs value is the value from the map. You can then use ${property-name} to refer to the property and its value. For example, if your map contains the key username with the value alice, the property placeholder ${username} will resolve to alice.