码迷,mamicode.com
首页 > 编程语言 > 详细

Log4j配置文件位置+Spring中数据源配置文件位置

时间:2014-07-29 15:15:58      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:log4j   spring   datasource   

一.Log4j配置文件位置

1.自动加载

应用程序启动时,默认情况下会到src目录下寻找log4j.xml配置文件,若不存在,会继续寻找log4j.properties文件,只要找到其中一个就会加载该配置文件内容。


2.手动加载

如果将log4j.properties(或log4j.xml)放到其它目录下,比如下图中的位置,应用程序就不能自动加载log4j的配置文件了,因为应用程序找不到该配置文件,你需要手动加载。

bubuko.com,布布扣

需要在应用程序启动的代码中加入如下的代码:

//加载config文件夹下的log4j.properties
			String log4jPath=System.getProperty("user.dir")+"/config/log4j.properties";
			PropertyConfigurator.configure(log4jPath);

二.Spring中数据源配置文件位置

1.一般情况

比较常见的Spring加载数据源配置文件的方式如下:

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

这种方式是将dataSource.properties文件放在src的根目录下的。

2.其它位置

现在如果将dataSource.properties文件放在src同级的config的目录下,上面的配置方式就不行了,正确的配置方式如下:

<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>file:config/dataSource.properties</value>
			</list>
		</property>
	</bean>

交流探讨到我的新浪微博:http://weibo.com/tianrui1990

Log4j配置文件位置+Spring中数据源配置文件位置,布布扣,bubuko.com

Log4j配置文件位置+Spring中数据源配置文件位置

标签:log4j   spring   datasource   

原文地址:http://blog.csdn.net/windrui/article/details/38266549

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!