Spring Boot: v2.6.7 with YAML application.yaml
I'm aware that there's the ability to put map keys in square brackets to enable explicit retention of things like whitespace and periods. However, that's not quite the same as expecting the keys to be resolved appropriately.
Expectation:
For a system with USERNAME environment variable = Bob, and with an application.yaml file that looks something like this:
map:
"${USERNAME}": 5
default: 1
I'd expect a @ConfigurationProperties similar to:
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
@Data
@ConfigurationProperties
public class Config {
private Map<String, Integer> map;
}
to have the map variable resolve to:
Bob: 5
default: 1
Actual:
USERNAME: 5
default: 1
Thanks in advance for taking a look!
Comment From: wilkinsona
This is to be expected as placeholders are only replaced in property values. You may be able to use square brackets to retain ${USERNAME} and then perform some post-processing of the map yourself using org.springframework.core.env.PropertyResolver.resolvePlaceholders(String).
Comment From: tomcruise81
Thanks so much. I'll look into doing that.