spring @Value示例

springmvc.xml中配置

<!-- 引入配置文件 -->
<bean id="propertyConfigurer"  
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
         <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>
                 <value>classpath:config.properties</value>
            </list>
        </property>  
</bean> 

properties路径:

properties配置

#测试环境地址
testEnvir=https://opentest.haiermoney.com:18980

#签约平台
#文件上传接口
sign.fileUploadUrl=/services/singlefile/upload/v1.0

调用:

    @Value("${testEnvir}")
    private String testEnvir; 
    
    @Value("${sign.fileUploadUrl}")
    private  String uploadUrl; 

注意:该种配置不能与以下配置同时存在spring中

<context:property-placeholder location="classpath:jdbc.properties"/>

  

原文地址:https://www.cnblogs.com/SunAutumn/p/8027979.html