Sunday, June 21, 2015

Spring - Get the values of property files using @value anotation

In the file x.properties
xx.test.flag.list=X,Y,Z

In the spring configuration file:-

<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/x.properties</value>
</list>
</property>
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>

And in the java class file using @Value anotation.

@Value("#{'${xx.test.flag.list}'.split(',')}")
private List<String> flagsList;