一個.Log4j配置文件位置
1.加載自己主動
當應用程序啟動,缺省情況下,這將是src文件夾搜索log4j.xml型材。如果不存在。我們將繼續尋找log4j.properties文件,僅僅要找到當中一個就會載入該配置文件內容。
2.手動載入
假設將log4j.properties(或log4j.xml)放到其他文件夾下,比方下圖中的位置,應用程序就不能自己主動載入log4j的配置文件了,由於應用程序找不到該配置文件,你須要手動載入。
須要在應用程序啟動的代碼中增加例如以下的代碼:
//載入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
版權聲明:本文博客原創文章,博客,未經同意,不得轉載。