我可能在这里做了些蠢事。 There is something (smallish) wrong with my dropwizard setup。运行着色jar工作正常,但在执行集成测试时,我收到此警告:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/graphhopper/web/target/graphhopper-web-0.11-SNAPSHOT.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/user/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
INFO [2018-04-08 18:44:27,653] org.eclipse.jetty.util.log: Logging initialized @1090ms to org.eclipse.jetty.util.log.Slf4jLog
其中graphhopper-web-0.11-SNAPSHOT.jar是带有dropwizard的阴影jar(带有logback)。
这个usually means多个slf4j绑定在类路径上,但我可以拒绝这个理论,只有slf4j-api存在,加上dropwizard的logback依赖。我还用Netbeans和
分析了依赖图 mvn dependency:tree -Dverbose -Dincludes=org.slf4j
(参见输出here) 但是找不到有问题的东西。
是否可以将阴影jar(带有logback)与mvn clean install
的其他jar(包括logback)一起放入类路径中?我怎么能避免这个?
通过以下方式重现:
git clone https://github.com/graphhopper/graphhopper
cd web
mvn clean install
请参阅this issue。
答案 0 :(得分:3)
将您的代码导入我的intellij社区版,并在Web模块的pom.xml中的所有依赖项中添加以下排除项。它解决了问题。您可能已在相应的模块中进行了更改。
示例:
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>1.2.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
答案 1 :(得分:2)
问题是jar logback-classic-1.2.3.jar
有一个实际的文件/org/slf4j/impl/StaticLoggerBinder.class
,因此jar排除不起作用。
您需要更改configuration
maven-shade-plugin
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<filters>
<filter>
<artifact>ch.qos.logback:logback-classic</artifact>
<excludes>
<exclude>org/slf4j/impl/**</exclude>
</excludes>
</filter>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
一旦你这样做,一切都很好,警告就消失了
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< com.graphhopper:graphhopper-web >-------------------
[INFO] Building GraphHopper Web 0.11-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ graphhopper-web ---
[INFO] Deleting /Users/tarun.lalwani/Desktop/tarunlalwani.com/tarunlalwani/workshop/ub16/so/graphhopper/web/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ graphhopper-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 118 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ graphhopper-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 19 source files to /Users/tarun.lalwani/Desktop/tarunlalwani.com/tarunlalwani/workshop/ub16/so/graphhopper/web/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ graphhopper-web ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ graphhopper-web ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 9 source files to /Users/tarun.lalwani/Desktop/tarunlalwani.com/tarunlalwani/workshop/ub16/so/graphhopper/web/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.19.1:test (default-test) @ graphhopper-web ---
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.graphhopper.http.WebHelperTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.151 sec - in com.graphhopper.http.WebHelperTest
Running com.graphhopper.http.IPFilterTest
20:29:46.762 [main] DEBUG com.graphhopper.http.IPFilter - whitelist:[4.5.67.1, 1.2.3.4]
20:29:46.765 [main] DEBUG com.graphhopper.http.IPFilter - blacklist:[8.9.7.3]
20:29:46.765 [main] DEBUG com.graphhopper.http.IPFilter - blacklist:[4.5.67.1, 1.2.3.4]
20:29:46.766 [main] DEBUG com.graphhopper.http.IPFilter - whitelist:[4.5.67.1, 1.2.3.4]
20:29:46.766 [main] DEBUG com.graphhopper.http.IPFilter - whitelist:[1.2.3*, 4.5.67.1, 7.8.*.3]
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.003 sec - in com.graphhopper.http.IPFilterTest
Results :
Tests run: 8, Failures: 0, Errors: 0, Skipped: 0
编辑-1:2018年4月26日
来自https://github.com/graphhopper/graphhopper/issues/1328
的更新我认为问题在于您在构建的验证阶段将Dropwizard应用程序集成测试作为集成测试运行。在创建着色jar的包阶段之后调用此阶段,并用它替换原始jar。
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /home/travis/build/graphhopper/graphhopper/web/target/graphhopper-web-0.11-SNAPSHOT.jar with /home/travis/build/graphhopper/graphhopper/web/target/graphhopper-web-0.11-SNAPSHOT-shaded.jar
因此,您在类路径中有两个包含两个slf4j绑定的jar(graphhopper-web-0.11-SNAPSHOT和logback-classic-1.2.3.jar)。没有必要创建一个阴影jar来运行针对Dropwizard应用程序的集成测试,它可以作为单元测试运行。因此,如果您将graphhopper-web配置为在测试阶段运行其集成测试,则不会发出警告:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<excludes>
<exclude>com.graphhopper.http.**</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>-Xmx100m -Xms100m</argLine>
<includes>
<include>com.graphhopper.http.**</include>
</includes>
</configuration>
</plugin>
另一种选择是将它们从* IT重命名为* Test,因此它们不会自动匹配为集成测试。