log4j配置

上一篇 / 下一篇  2012-05-31 00:12:07 / 个人分类:123

 

1)spring
    配置文件applicationContext.xml的位置,把他放在project下面以后,我们需要通过下面的方法来获取,而不是原先的ClassPathXmlApplicationContext("applicationContext.xml");了

Java代码
  1. ApplicationContext context = new FileSystemXmlApplicationContext(System.getProperty("user.dir") + \\applicationContext.xml);

   配置文件log4j.propeties,他的配置也可以放在project下面,但需要手动设置起路径.一般都把他放在main方法的第一行,代码如下:

Java代码 复制代码
  1. PropertyConfigurator.configure(System.getProperty("user.dir") + "\\log4j.properties");  

  总结:在J2EE中使用,配置方法相比在J2SE下更强大,不需要写代码,就能实现LOG4J的配置通过Spring会比较灵活,而spring的文件配置路径,仍然需要使用

Java代码 复制代码 
  1. 1)System.getProperty("user.dir")   
  2. 2)或者String url = this.getClass().getClassLoader().getResource("/").toString();   
  3.     url = url.substring(0, url.length() - 8);  

TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-05  
   1234
567891011
12131415161718
19202122232425
262728293031 

我的存档

数据统计

  • 访问量: 1477
  • 日志数: 6
  • 建立时间: 2012-05-27
  • 更新时间: 2012-05-31

RSS订阅

Open Toolbar