首页 > 编程语言 > 详细

spring 读取properties的两种方法

时间:2017-05-19 09:31:40      阅读:284      评论:0      收藏:0      [点我收藏+]

一:直接使用context命名空间

如:

<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:websocket="http://www.springframework.org/schema/websocket"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	   http://www.springframework.org/schema/beans/spring-beans.xsd
	   http://www.springframework.org/schema/websocket
       http://www.springframework.org/schema/websocket/spring-websocket.xsd
	   http://www.springframework.org/schema/context 
	   http://www.springframework.org/schema/context/spring-context.xsd">



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

二:在配置文件里配置PropertyPlaceholderConfigurer

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
	<property name="locations" value="classpath:jdbc.properties" />
</bean>

然后在须要的地方直接下面方式引用

<property name="url" value="${jdbc.url}"/>


spring 读取properties的两种方法

原文:http://www.cnblogs.com/lxjshuju/p/6876589.html

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