Weblogic 和 log4j

Weblogic and log4j

我正在使用 weblogic 12c 和 jdk 1.8。 在我的应用程序开始时,有 BeEnvironment class 以这种模式加载内部 log4j.properties:

    if (Thread.currentThread().getContextClassLoader().getResourceAsStream(CONFIGURATION + File.separator + mwaEnv + File.separator + Constants.LOG_4_j) != null) { 
        System.out.println("CARICO LE IMPOSTAZIONI DI LOG4J DA: " + CONFIGURATION + File.separator + mwaEnv + File.separator + Constants.LOG_4_j);
        PropertyConfigurator.configure(this.getClass().getClassLoader().getResource(CONFIGURATION + File.separator + mwaEnv + File.separator + Constants.LOG_4_j));
    }       

字符串"CONFIGURATION + File.separator + mwaEnv + File.separator + Constants.LOG_4_j"是文件log4j.properties所在的路径。 此路径在项目的class路径(src/main/resources)下。

问题是 weblogic 没有找到文件 log4j.properties。 webphere 应用程序服务器中的相同代码运行良好。 也许我必须在 weblogic.xml?

中配置一些标签

我将 File.Separator 替换为“/”以获得属性文件的正确路径。这样一切顺利。 我认为问题在于 weblogic 安装在 Windows 上。 File.separator 在类似 windows 的模式下是“\”。而 Weblogic 希望“/”从类路径中获取属性文件。