Using the new @PropertySource
annotation in Spring 3.1, how can you access multiple property files with Environment?
Currently I have:
@
there are two different approaches: the first one is to use the PropertyPlaceHolder in your applicationContext.xml: beans-factory-placeholderconfigurer
the namespace to add is xmlns:context="http://www.springframework.org/schema/context"
If you want a direct access of a key to a String variable in your controller, use:
@Value("${some.key}")
private String valueOfThatKey;
The second approach is to use the util:properties
in you applicationContext.xml:
using the namesapce xmlns:util="http://www.springframework.org/schema/util"
schemaLocations: http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
Then in your Controller:
@Resource(name="fileA")
private Properties propertyA;
@Resource(name="fileB")
private Properties propertyB;
If you want a value from the files, just use the method getProperty(String key)