spring 读取properties的两种方法
2013-10-23 11:50
393 查看
1.在配置文件中配置PropertyPlaceholderConfigurer
然后在需要的地方直接以下方式引用:
2.在配置文件中加入
beans的命名空间声明如下:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="classpath:com/foo/jdbc.properties"/> </bean>
然后在需要的地方直接以下方式引用:
<property name="url" value="${jdbc.url}"/>
2.在配置文件中加入
beans的命名空间声明如下:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">[/code]
用到了xmlns:context=http://www.springframework.org/schema/context
配置如下:<context:property-placeholder location="dbconf.properties"/>
相关文章推荐
- Spring读取外部的.properties文件内容并设置给bean的两种方法
- spring 读取properties的两种方法
- Spring 读取properties的两种方法
- spring 读取properties的两种方法
- spring 读取properties的两种方法
- spring 读取properties的两种方法
- Spring中配置和读取多个Properties文件的方式方法
- spring学习笔记——摘录:对properties文件引用的两种方法
- Spring afterPropertiesSet方法读取系统配置文件实例
- Spring读取properties文件出现乱码的解决方法
- 使用spring注解方法读取properties文件中值
- 关于spring在程序中读取properties文件配置项的方法
- Spring读取properties文件出现乱码的解决方法
- spring中无法读取properties文件中属性的解决方法
- Spring: 读取 .properties 文件地址,json转java对象,el使用java类方法相关 (十三)
- 如何读取.properties文件配置的两种方法
- 使用spring注解方法读取properties文件中值
- springBoot使用Controller读取配置文件两种方式&读取自定义配置方法
- spring读取properties的方法
- spring读取xml的两种方法