spring @value goes back to the value in the configuration file

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

copy code
<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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326175298&siteId=291194637
Recommended