您的位置:首页 > 编程语言 > Java开发

spring读取properties文件

2015-11-27 18:37 429 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: