log4j2.0如何加载指定路径的配置文件?

解决方案 »

  1.   

    要的是代码还是流程?
    代码:URL url  =  UserServiceImpl. class .getResource( " /config/log4j.properties " );
    Properties properties  =   new  Properties();
    try  {
         properties.load( new  InputStreamReader(url.openStream()));
        }  catch  (IOException e) {
            e.printStackTrace();
        }
    PropertyConfigurator.configure(properties);
      

  2.   

    1楼这个是log4j 1.x版本的吧,log4j2.0版本为什么我没有找到PropertyConfigurator这个类
      

  3.   

    在java工程的system proterty中设置。
    也就是在VM arguments中设置"-Dlog4j.configurationFile="D:\learning\blog\20130115\config\LogConfig.xml"把“D:\learning\blog\20130115\config\LogConfig.xml”替换成你指定的配置文件的路径即可。
      

  4.   

    为甚不把log4j.properties放在src下
      

  5.   

    web.xml 配置
    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>