initializationError(AbstractServiceTest) : org.slf4j.spi.LocationAwareLogger.log(String ; Throwable)

initializationError(AbstractServiceTest) : org.slf4j.spi.LocationAwareLogger.log(String ; Throwable)

我在使用 Spring 和 Maven 时遇到问题。我的应用程序本身没有任何问题,但我现在尝试执行 SpringJUnit4ClassRunner 测试,但它不再编译...

我遇到了问题:

initializationError(...) : org.slf4j.spi.LocationAwareLogger.log(String ; Throwable)

当范围是 test 时,这显然是我的依赖项中的一个问题,但我没有成功地看到确切的位置...... 这是我 运行 mvn dependencies:list:

时所有依赖项的列表
[INFO] ------------------------------------------------------------------------
[INFO] Building sfinx-service 0.4.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:list (default-cli) @ sfinx-service ---
[INFO] 
[INFO] The following files have been resolved:

[INFO]    org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
[INFO]    org.hibernate:hibernate-ehcache:jar:4.1.0.Final:compile
[INFO]    displaytag:displaytag:jar:1.2:compile
[INFO]    org.springframework:spring-beans:jar:4.1.0.RELEASE:compile
[INFO]    org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO]    cglib:cglib:jar:2.2.2:compile
[INFO]    org.jboss.logging:jboss-logging:jar:3.1.0.CR2:compile
[INFO]    javax.mail:mail:jar:1.4:compile
[INFO]    org.hibernate:hibernate-core:jar:4.1.0.Final:compile
[INFO]    commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO]    org.aspectj:aspectjrt:jar:1.6.8:compile
[INFO]    org.springframework:spring-context-support:jar:4.1.0.RELEASE:compile
[INFO]    org.hibernate:hibernate-validator:jar:4.1.0.Final:compile
[INFO]    commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO]    log4j:log4j:jar:1.2.17:compile
[INFO]    com.google.guava:guava:jar:11.0.2:compile
[INFO]    xml-apis:xml-apis:jar:1.0.b2:compile
[INFO]    javax.activation:activation:jar:1.1:compile
[INFO]    org.hibernate:hibernate-entitymanager:jar:4.1.0.Final:compile
[INFO]    commons-logging:commons-logging:jar:1.1.3:compile
[INFO]    org.springframework.ldap:spring-ldap-core:jar:1.3.0.RELEASE:compile
[INFO]    antlr:antlr:jar:2.7.7:compile
[INFO]    net.sourceforge.jexcelapi:jxl:jar:2.6.12:compile
[INFO]    aopalliance:aopalliance:jar:1.0:compile
[INFO]    displaytag:displaytag-export-poi:jar:1.2:compile
[INFO]    org.hibernate:hibernate-validator-annotation-processor:jar:4.1.0.Final:compile
[INFO]    org.aspectj:aspectjweaver:jar:1.6.8:compile
[INFO]    asm:asm:jar:3.3.1:compile
[INFO]    com.lowagie:itext:jar:1.3:compile
[INFO]    commons-codec:commons-codec:jar:1.5:compile
[INFO]    junit:junit:jar:4.11:test
[INFO]    org.springframework:spring-test:jar:4.1.0.RELEASE:test
[INFO]    org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO]    org.springframework:spring-aop:jar:4.1.0.RELEASE:compile
[INFO]    com.mysema.querydsl:querydsl-core:jar:2.9.0:compile
[INFO]    com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO]    com.mysema.commons:mysema-commons-lang:jar:0.2.4:compile
[INFO]    org.springframework:spring-orm:jar:4.1.0.RELEASE:compile
[INFO]    org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO]    org.slf4j:jcl104-over-slf4j:jar:1.4.2:compile
[INFO]    commons-collections:commons-collections:jar:3.1:compile
[INFO]    org.springframework.security:spring-security-ldap:jar:3.0.5.RELEASE:compile
[INFO]    org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    net.sf.ehcache:ehcache-core:jar:2.6.3:compile
[INFO]    org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO]    org.hsqldb:hsqldb:jar:2.2.8:compile
[INFO]    org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO]    org.apache.poi:poi:jar:3.9:compile
[INFO]    org.springframework.security:spring-security-core:jar:3.0.5.RELEASE:compile
[INFO]    org.springframework:spring-tx:jar:4.1.0.RELEASE:compile
[INFO]    dom4j:dom4j:jar:1.6.1:compile
[INFO]    org.springframework:spring-jdbc:jar:4.1.0.RELEASE:compile
[INFO]    com.oracle:ojdbc14:jar:10.2.0.3.0:compile
[INFO]    commons-pool:commons-pool:jar:1.5.4:compile
[INFO]    org.springframework:spring-core:jar:4.1.0.RELEASE:compile
[INFO]    org.springframework:spring-context:jar:4.1.0.RELEASE:compile
[INFO]    org.springframework:spring-expression:jar:4.1.0.RELEASE:compile
[INFO]    displaytag:displaytag-portlet:jar:1.2:compile
[INFO]    com.mysema.querydsl:querydsl-jpa:jar:2.9.0:compile
[INFO]    javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO]    org.javassist:javassist:jar:3.15.0-GA:compile
[INFO]    commons-lang:commons-lang:jar:2.3:compile 

这是我模块的 pom.xml :

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
    <artifactId>sfinx</artifactId>
    <groupId>net.gdcw.sfinx</groupId>
    <version>0.4.0-SNAPSHOT</version>
</parent>

<artifactId>sfinx-service</artifactId>
<version>${project.parent.version}</version>
<name>sfinx-service</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <parent.basedir>${basedir}/..</parent.basedir>
</properties>

<build>
    <finalName>${final.name}</finalName>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven.jar.plugin.version}</version>
                <configuration>
                    <finalName>${project.name}-${project.version}</finalName>
                    <archive>
                        <manifestFile>${manifest.file.location}</manifestFile>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<dependencies>

    <!-- Internal projects -->
    <dependency>
        <groupId>net.gdcw.sfinx</groupId>
        <artifactId>sfinx-domain</artifactId>
        <version>${project.version}</version>
    </dependency>

    <dependency>
        <groupId>net.gdcw.sfinx</groupId>
        <artifactId>sfinx-dao</artifactId>
        <version>${project.version}</version>
    </dependency>

    <!-- Spring core -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Ldap -->
    <dependency>
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-ldap</artifactId>
        <version>3.0.5.RELEASE</version>
    </dependency>

    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator-annotation-processor</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <!-- Excel -->
    <dependency>
        <groupId>displaytag</groupId>
        <artifactId>displaytag-export-poi</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>displaytag</groupId>
        <artifactId>displaytag-portlet</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.9</version>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.jexcelapi</groupId>
        <artifactId>jxl</artifactId>
        <version>2.6.12</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>${slf4j.version}</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j.version}</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4</version>
    </dependency>


</dependencies>

这里是 master 中的依赖项 pom.xml :

<dependencies>

    <!-- Common dependencies -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
        <scope>compile</scope>
    </dependency>

</dependencies>

在此先感谢您的帮助, 最好的问候。

事实上,使用 mvn dependencies:tree 更有助于找出问题的根源。

这是因为我的列表中存在这种依赖关系:

[INFO] org.slf4j:jcl104-over-slf4j:jar:1.4.2:compile

造成问题的原因是:

slf4j 1.4.2 和 1.7.5 版本不兼容(参见compatibility report)因为org.slf4j.spi.LocationAwareLogger.log方法的参数列表已更改(添加Object[] p5):

slf4j 1.4.2:

LocationAwareLogger.log ( org.slf4j.Marker p1, String p2, int p3, String p4, Throwable p5 )

slf4j 1.7.5:

LocationAwareLogger.log ( org.slf4j.Marker p1, String p2, int p3, String p4, Object[] p5, Throwable p6 )

查看其他 SLF4J 版本的兼容性报告on this page

您可以通过 japi-compliance-checker 工具生成此类报告。


(解释来自:Logging framework incompatibility)。

我通过向捆绑错误 slf4j 版本的依赖项添加排除项来解决此问题:

    <dependency>
        <groupId>displaytag</groupId>
        <artifactId>displaytag-export-poi</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl104-over-slf4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

这样,slf4j.

之间没有版本冲突