当前位置: 首页 > 知识库问答 >
问题:

使用我得到的拖放向导的阴影罐:类路径包含多个SLF4J绑定

利稳
2023-03-14

我可能在这里做了一些愚蠢的事情。我的dropwizard设置有一些(小)问题。运行阴影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

其中graph hopper-we b-0.11-snapshot . jar是带dropwizard的阴影jar(带logback)。

这通常意味着类路径上有多个slf4j绑定,但我可以拒绝这种理论,因为只有SLF4JAPI,加上dropwizard的logback依赖。我还分析了Netbeans和的依赖关系图

mvn dependency:tree -Dverbose -Dincludes=org.slf4j

(参见此处的输出)但找不到有问题的东西。

会不会是阴影的jar(带有logback)以某种方式与其他jar(包括logback)一起放入类路径中以用于mvn净安装?我如何避免这种情况?

通过以下方式复制:

git clone https://github.com/graphhopper/graphhopper
cd web
mvn clean install

看这个问题。

共有2个答案

澹台文博
2023-03-14

问题是 jar 日志-经典-1.2.3.jar有一个实际的文件 /org/slf4j/impl/静态记录器.class,所以 jar 排除将不起作用。

您需要更改< code>maven-shade-plugin的< code >配置

<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

编辑日期: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

因此,类路径中有两个 jar,其中包含两个 slf4j 绑定(图形虎-web-0.11-快照和日志-经典-1.2.3.jar)。无需创建一个阴影罐来针对 Dropwizard 应用程序运行集成测试,它可以作为单元测试运行。因此,如果您将图形虎网配置为在测试阶段运行其集成测试,则不会出现警告:

        <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,这样它们就不会自动匹配为集成测试。

邵鸿福
2023-03-14

将您的代码导入到我的intellij社区版本中,在pom.xml Web模块中的所有依赖项中添加了如下排除。它解决了给定问题的问题。您可能已经在相应的模块中进行了更改。

示例:

<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>
</dependency>
 类似资料:
  • 我得到以下错误。似乎有多个日志记录框架绑定到SLF4J。不知道该怎么解决。非常感谢任何帮助。

  • 我的应用程序服务器ibm WebSphere。我在应用程序服务器日志中得到以下错误。哪里可以设置websphere? [19.09.2012 14:56:54:940 EEST]0000000a SystemErr R SLF4J:类路径包含多个SLF4J绑定。 [19.09.2012 14:56:54:940 EEST]0000000a SystemErr R SLF4J:在[wsjar:fil

  • 我在运行java代码时遇到以下运行时异常。有人能帮我解决绑定冲突吗。

  • 我在netbeans中有一个纯Java项目,我得到的警告是: 当然,我搜索了警告,但所有的答案都与用maven或pom.xml文件删除重复绑定有关。但是我没有pom.xml文件,也没有使用Maven。 那么如何排除绑定呢?

  • 我已经在我的应用程序中使用-SLF4J创建了cutom日志,如下链接:, http://javaeenotes.blogspot.com/2011/12/custom-slf4j-logger-adapter.html 它的工作与样本HelloWorldProgram这样很好, 但是如果我将它集成到maven项目中,使用spring创建日志文件, 我得到以下错误。尝试了许多不同的方法来解决这个问题