5

project Apom.xml依存関係があるslf4j

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.10</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.10</version>
    </dependency>

今、私は次の依存関係project Bを持っている別のものを持っていますpom.xmlslf4j

   </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.0.3</version>
    </dependency>

2 つのプロジェクトを統合する必要がありますが、バージョンが異なるとうまく連携できません。だからこれは私が試みたものですアプローチ1 - に変更し た 後の
slf4jのアップグレードproject Apom.xml

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.4</version>
    </dependency>

ビルドエラーが表示されるようになりました

SLF4J: The requested version 1.5.10 by your slf4j binding is not compatible with [1.6]
SLF4J: See http://www.slf4j.org/codes.html#version_mismatch for further details.

テストは失敗するようです

java.lang.IllegalStateException: Failed to load ApplicationContext
    at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:308)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
    at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
    at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:220)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:301)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:303)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:240)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 

アプローチ 2 - slf4j のダウングレードproject B

pom.xml次のように 変更した後

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.10</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.0.3</version>
    </dependency>

テストのエラーは次のように表示されます

testPutDocument(com.org.sparrow.business.persist.MongoServiceTest): org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
  testPutDocuments(com.org.sparrow.business.persist.MongoServiceTest): org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
  testGetDocument(com.org.sparrow.business.persist.MongoServiceTest): org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;  

この問題にアプローチする最善の方法は何ですか?

UPDATE 依存関係ツリーはこちら

[INFO] +- commons-codec:commons-codec:jar:1.4:compile
[INFO] +- spy:spymemcached:jar:2.6:compile
[INFO] +- com.google.code.findbugs:annotations:jar:1.3.9:compile
[INFO] +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] +- redis.clients:jedis:jar:1.4.0:compile
[INFO] +- com.googlecode:hibernate-memcached:jar:1.2.2:compile
[INFO] |  \- spy:memcached:jar:2.4.2:compile
[INFO] +- j2ssh:core:jar:0.2.9-SR:compile
[INFO] +- emma:maven-emma-plugin:jar:0.5:test
[INFO] |  +- ant:ant:jar:1.6.3:test
[INFO] |  \- emma:emma_ant:jar:2.0.5312:test
[INFO] +- emma:emma:jar:2.0.4217:test
[INFO] |  +- commons-jelly:commons-jelly-tags-regexp:jar:1.0:test
[INFO] |  \- regexp:regexp:jar:1.3:test
[INFO] +- org.apache.commons:commons-email:jar:1.1:compile
[INFO] |  +- javax.mail:mail:jar:1.4:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- hsqldb:hsqldb:jar:1.8.0.7:test
[INFO] +- org.aspectj:aspectjrt:jar:1.6.1:compile
[INFO] +- org.aspectj:aspectjweaver:jar:1.6.1:compile
[INFO] +- org.springframework:spring-context-support:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:3.0.5.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-tx:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:3.0.5.RELEASE:compile
[INFO] |  +- org.springframework:spring-asm:jar:3.0.5.RELEASE:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-context:jar:3.0.5.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-agent:jar:2.5.6:compile
[INFO] +- org.springframework:spring-aop:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-aspects:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-core:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-web:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-cas-client:jar:3.0.5.RELEASE:compile
[INFO] |  \- org.jasig.cas:cas-client-core:jar:3.1.10:compile
[INFO] +- org.springframework.security:spring-security-config:jar:3.0.5.RELEASE:compile
[INFO] +- org.jasig.cas.client:cas-client-core:jar:3.2.0:compile
[INFO] +- org.hibernate:hibernate-envers:jar:3.5.6-Final:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:3.5.6-Final:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  |  \- javax.transaction:jta:jar:1.1:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.0.Final:compile
[INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.2.0.Final:compile
[INFO] |  +- org.hibernate:hibernate-annotations:jar:3.5.6-Final:compile
[INFO] |  \- org.hibernate:hibernate-tools:jar:3.2.0.ga:compile
[INFO] |     +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] |     +- freemarker:freemarker:jar:2.3.8:compile
[INFO] |     \- org.hibernate:jtidy:jar:r8-20060801:compile
[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.6-Final:compile
[INFO] |  \- cglib:cglib:jar:2.2:compile
[INFO] |     \- asm:asm:jar:3.1:compile
[INFO] +- org.hibernate:hibernate-c3p0:jar:3.5.6-Final:compile
[INFO] +- org.hibernate:hibernate-validator:jar:4.1.0.Final:compile
[INFO] |  \- javax.validation:validation-api:jar:1.0.0.GA:compile
[INFO] +- org.springframework:spring-hibernate3:jar:2.0.8:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.5.10:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.10:compile
[INFO] +- javassist:javassist:jar:3.4.GA:compile
[INFO] +- c3p0:c3p0:jar:0.9.1.2:compile
[INFO] +- eu.medsea:utils:jar:1.0:compile
[INFO] +- velocity-tools:velocity-tools-view:jar:1.4:compile
[INFO] +- velocity:velocity:jar:1.5:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.1:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.1:compile
[INFO] |  \- oro:oro:jar:2.0.8:compile
[INFO] +- axis:axis:jar:1.4:compile
[INFO] |  +- org.apache.axis:axis-jaxrpc:jar:1.4:compile
[INFO] |  +- org.apache.axis:axis-saaj:jar:1.4:compile
[INFO] |  \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] +- junit:junit:jar:4.8.2:compile
[INFO] +- org.jmock:jmock-junit4:jar:2.5.1:compile
[INFO] |  \- org.jmock:jmock:jar:2.5.1:compile
[INFO] |     +- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO] |     \- org.hamcrest:hamcrest-library:jar:1.1:compile
[INFO] +- xalan:xalan:jar:2.7.0:compile
[INFO] |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- xerces:xercesImpl:jar:2.4.0:compile
[INFO] +- jdom:jdom:jar:1.0:compile
[INFO] +- net.sourceforge.jexcelapi:jxl:jar:2.6:compile
[INFO] +- log4j:log4j:jar:1.2.15:compile
[INFO] +- jaxen:jaxen:jar:1.1.1:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  \- xom:xom:jar:1.0:compile
[INFO] |     +- xerces:xmlParserAPIs:jar:2.6.2:compile
[INFO] |     \- com.ibm.icu:icu4j:jar:2.6.1:compile
[INFO] +- mapquest:mapquest:jar:5.3.0:compile
[INFO] +- jfree:jfreechart:jar:1.0.0:compile
[INFO] |  \- jfree:jcommon:jar:1.0.0:compile
[INFO] +- org.fraid.fraid:fraid:jar:1.5:compile
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO] |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.13:compile
[INFO] +- joda-time:joda-time:jar:1.6:compile
[INFO] +- nl.jqno.equalsverifier:equalsverifier:jar:0.6.2:test
[INFO] |  +- org.objenesis:objenesis:jar:1.1:test
[INFO] |  \- cglib:cglib-nodep:jar:2.2:test
[INFO] +- org.easymock:easymockclassextension:jar:2.5.2:test
[INFO] |  \- org.easymock:easymock:jar:2.5.2:test
[INFO] +- org.springframework:spring-test:jar:3.0.5.RELEASE:compile
[INFO] +- cdyne:cdyne:jar:3.0:compile
[INFO] |  \- javax.xml:jaxrpc-api:jar:1.1:compile
[INFO] +- json:json:jar:0.0.1:compile
[INFO] +- org.dbunit:dbunit:jar:2.4.8:test
[INFO] +- org.mongodb:mongo-java-driver:jar:2.2:compile
[INFO] +- com.google.code.gson:gson:jar:1.4:compile
[INFO] +- xml-security:xmlsec:jar:1.3.0:compile
[INFO] \- javatar:javatar:jar:2.5:compile
4

2 に答える 2

1

他のプロジェクトにライブラリとして含める Jar プロジェクトは、slf4j-api 以外の POM に何も含めないでください。実装を決定するのは、最終的なプロジェクト (つまり、この例ではプロジェクト A) 次第です。プロジェクト B のテストでは、slf4j-log4j12 や log4j 自体などの実装を含めることは許容されますが、これらはtestMaven でスコープする必要があります。

于 2012-07-17T21:24:42.663 に答える
1

あなたの質問では、プロジェクトAの pom.xml で slf4j-api と slf4j-log4j12 をバージョン1.6.4にアップグレードしたと述べていますが、投稿した依存関係ツリーには slf4j-api と slf4j-log4j12 バージョン1.5.0が記載されています。slf4j-api とそのバインディングのバージョンが一致するようにバージョンを決めれば問題ありません。

他の依存関係が SLF4J に対して宣言している SLF4J のバージョンは関係ありません。クライアントの観点から見ると、slf4j のすべてのバージョンはバイナリ互換です。

于 2012-07-17T15:43:13.530 に答える