Simplify reading configuration files with Spring 3's @value
Spring 3 supports @value annotation to obtain the configuration value in the properties file, which greatly simplifies the code for reading the configuration file.
1. Configure the properties file in the applicationContext.xml file
<bean id="configPropertys" class="org.springframework.beans.factory.config.PropertysFactionBean"> <property name="locations"> <list> <value>classpath*:system.properties</value>
<value>classpath*:db.properties</value>
</list> </property> </bean>
2. Use the @value annotation in the controller to get the value of the configuration file
@Value("#{configPropertys['server-oa.web.uploadPath']}")
private String uploadPath;
Even if an initial value is assigned to a variable, the value in the configuration file will prevail.