首页 > 编程语言 > 详细

spring读取properties文件

时间:2015-11-27 20:01:24      阅读:726      评论:0      收藏:0      [点我收藏+]

1.方式一

<util:properties id="meta" location="classpath:config/metainfo.properties" />

@Value("#{meta[‘pubVersion‘]}")
    private String pubVersion

 

2方式二:

    <bean id="configPropertiesTest" class="org.springframework.beans.factory.config.PropertiesFactoryBean">  
       <property name="locations">  
           <list>  
               <value>file:${global.config.path}/opc/opc-business/jdbc.write.properties</value>
               <value>file:${global.config.path}/opc/opc-business/jdbc.read.properties</value>
           </list>  
       </property>  
    </bean>

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">  
        <property name="properties" ref="configPropertiesTest" />  
    </bean>

 

  @Value("#{configPropertiesTest[‘jdbc.read.username‘]}")
      private String testKey;

 

启动时加入参数 -Dglobal.config.path=E:\opc_workspace\opc\conf

spring读取properties文件

原文:http://www.cnblogs.com/liuzy2014/p/5001487.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!