I have a properties file that I'm registering with Spring through XML, using the property-placeholder
element:
<context:property-placeholder location="classpath:foo.properties" />
I can access properties using @Value
annotations, e.g.
@Value("${prefs.key}")
private String prefValue;
but I also need to access properties via the Spring Environment, e.g.
@Autowired
private Environment env;
public String getValue(String key) {
return env.getProperty(key);
}
getValue()
here always returns null
, even for keys defined in the properties file, because it seems that using <property-placeholder>
does not expose properties to the Environment. Is there a way to force properties loaded this way to be accessible via the Environment?