4

I have a maven war project which depends on an EJB maven project. The EJB project handles all business logic including DB access through Hibernate. Both projects are JEE6 and run on glassfish 3.1.2 using maven. I'm currently trying to configure Log4j to work (also log hibernate) in the scenario described. I have the following log4j.xml file in my ejb's src/main/resources folder (I'm that it is in the classpath):

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

    <log4j:configuration xmlns:log4j=
                "http://jakarta.apache.org/log4j/"
                        debug="false">

        <appender name="consoleAppender"
                class="org.apache.log4j.ConsoleAppender">
            <param name="Threshold" value="INFO" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%d
                %-5p  [%c{1}] %m %n" />
            </layout>
        </appender>

        <logger name="javabeat.net.log4j" additivity="false" >
            <level value="INFO" />
            <appender-ref ref="consoleAppender"/>
        </logger>
    </log4j:configuration>

I keep getting this error from log4j:

SEVERE: log4j:ERROR A "org.apache.log4j.xml.DOMConfigurator" object is not assignable to a "org.apache.log4j.spi.Configurator" variable.

SEVERE: log4j:ERROR The class "org.apache.log4j.spi.Configurator" was loaded by

SEVERE: log4j:ERROR [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)] whereas object of type

SEVERE: log4j:ERROR "org.apache.log4j.xml.DOMConfigurator" was loaded by [WebappClassLoader (delegate=true; repositories=WEB-INF/classes/)].

SEVERE: log4j:ERROR Could not instantiate configurator [org.apache.log4j.xml.DOMConfigurator].

SEVERE: log4j:WARN No appenders could be found for logger (org.hibernate.type.BasicTypeRegistry).

SEVERE: log4j:WARN Please initialize the log4j system properly.

SEVERE: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

I'm out of ideas thx for the help

4

1 回答 1

0

http://forum.spring.io/forum/spring-projects/batch/76295-log4j-classloader-problem

您好,您提到的问题几乎总是当您有一个 web 应用程序时,它们的 lib 和 tomcat lib 目录中都有 log4j.jar,就像我发布的链接中解释的那样,所以您必须选择,在哪里是 log4j,在所有 webapps lib 文件夹中或仅在 tomcat lib 目录中:)

更新:

此外,您必须避免在 tomcat lib 和 webapp lib 目录中复制 commons-logging.jar。

问候

于 2014-08-05T14:51:35.760 回答