I am trying to dynamically access properties from Spring's Abstraction of Environment Properties .
I declare my property files as follows:
<context:property-placeholder location="classpath:server.common.properties, classpath:server.${my-environment}.properties" />
In the server.test.properties properties server.test.properties I define the following:
myKey=foo
Then, given the following code:
@Component public class PropertyTest { @Value("${myKey}") private String propertyValue; @Autowired private PropertyResolver propertyResolver; public function test() { String fromResolver = propertyResolver.getProperty("myKey"); } }
When I run this code, I end with propertyValue='foo' , but fromResolver=null ;
Getting propertyValue means that properties are being read (and I know this from other parts of my code). However, trying to find them dynamically does not work.
Why? How can I dynamically search for property values without using @Value ?
source share