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

SLF4J:类路径包含多个SLF4J绑定使用selenium-server时出错

於意蕴
2023-03-14

使用selenium-server-4.0.0-alpha-5.jargerrit-acceptance-framework-3.1.4.jar时,如何解决错误类路径包含多个SLF4J绑定

错误堆栈跟踪:

[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
===============================================

共有1个答案

桓宜
2023-03-14

此错误消息...

Class path contains multiple SLF4J bindings.

...暗示类路径上存在多个SLF4J绑定。

根据文档:

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

从错误stacktrace可以明显看出,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绑定。例如,要从selenium-server-4.0.0-alpha-5.jar中排除staticloggerbinder.class:

</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>

作为替代方法,您还可以从gerrit-acceptance-framework-3.1.4.jar中排除staticloggerbinder.class

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

 类似资料: