0

如何解决错误 Class path contains multiple SLF4J bindings while using selenium-server-4.0.0-alpha-5.jarandgerrit-acceptance-framework-3.1.4.jar

错误堆栈跟踪:

[RemoteTestNG] detected TestNG version 7.2.0
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/DELL/Desktop/selenium/selenium-server-4.0.0-alpha-5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/DELL/.m2/repository/com/google/gerrit/gerrit-acceptance-framework/3.1.4/gerrit-acceptance-framework-3.1.4.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 [org.slf4j.impl.JDK14LoggerFactory]
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}) on port 24218
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}) on port 48737
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987@{#882}) on port 5045
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.

===============================================
Suite
Total tests run: 3, Passes: 0, Failures: 3, Skips: 0
===============================================
4

1 回答 1

0

此错误消息...

Class path contains multiple SLF4J bindings.

...意味着在类路径上存在多个 SLF4J 绑定。


在类路径上发现了多个绑定

根据文档

SLF4J API 旨在一次绑定一个且仅一个底层日志框架。如果类路径上存在多个绑定,SLF4J 将发出警告,列出这些绑定的位置。

从错误堆栈跟踪很明显,这StaticLoggerBinder.class似乎在以下两个类路径中都可用:

  • C:/Users/DELL/Desktop/selenium/selenium-server-4.0.0-alpha-5.jar!/org/slf4j/impl
  • C:/Users/DELL/.m2/repository/com/google/gerrit/gerrit-acceptance-framework/3.1.4/gerrit-acceptance-framework-3.1.4.jar!/org/slf4j/impl

解决方案

当类路径上有多个绑定可用时,请选择一个且仅一个您希望使用的绑定,然后删除其他绑定。SLF4J 在此警告中提供的位置列表通常提供了足够的信息来识别依赖关系,该依赖项将不需要的 SLF4J 绑定传递到您的项目中。因此,在您的项目pom.xml文件中,您必须在声明不道德的依赖项时排除其中一个 SLF4J 绑定。例如,StaticLoggerBinder.class要从中排除selenium-server-4.0.0-alpha-5.jar

</dependencies>
  <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.X</version>

    <exclusions>
      <exclusion> 
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
      </exclusion>
    </exclusions>
  </dependency>
</dependencies>

作为替代方案,您还可以排除StaticLoggerBinder.classfromgerrit-acceptance-framework-3.1.4.jar

注意:SLF4J 发出的警告只是一个警告。即使存在多个绑定,SLF4J 也会选择一个日志框架/实现并与之绑定。SLF4J 选择绑定的方式是由 JVM 决定的,并且出于所有实际目的应该被认为是随机的。从 1.6.6 版本开始,SLF4J 将命名它实际绑定到的框架/实现类。

于 2020-05-21T19:15:35.773 回答