在web環(huán)境中加載log4j的配置文件時(shí)在web.xml中寫(xiě)配置即可,在非web環(huán)境中加載log4j.PRoperties需要在main方法中添加
PropertyConfigurator.configure("log4j.properties")
但是在運(yùn)行過(guò)程中出現(xiàn)filenotfondexception,按網(wǎng)上說(shuō)的把配置文件放在src目錄下還是不能加載成功
此時(shí)總結(jié)了幾種解決辦法
1). 用絕對(duì)路徑,不推薦;
PropertyConfigurator.configure("D/workspace/test/src/log4j.properties")
2). 使用相對(duì)路徑:
a). 將log4j文件置于src/目錄下,配置中,PropertyConfigurator.configure("src/log4j.properties");
b). 將log4j文件置于項(xiàng)目的根下,配置中,PropertyConfigurator.configure("log4j.properties");
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注