spring读取properties文件

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

posted @ 2015-11-27 18:37  人在囧途-博客  阅读(678)  评论(0编辑  收藏  举报