selenium - SLF4J:类路径包含使用 selenium-server 的多个 SLF4J 绑定错误
问题描述
如何解决错误 Class path contains multiple SLF4J bindings while using selenium-server-4.0.0-alpha-5.jar
andgerrit-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
===============================================
解决方案
此错误消息...
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.class
fromgerrit-acceptance-framework-3.1.4.jar
注意:SLF4J 发出的警告只是一个警告。即使存在多个绑定,SLF4J 也会选择一个日志框架/实现并与之绑定。SLF4J 选择绑定的方式是由 JVM 决定的,并且出于所有实际目的应该被认为是随机的。从 1.6.6 版本开始,SLF4J 将命名它实际绑定到的框架/实现类。
推荐阅读
- javascript - 在 NodeJs 中使用导入“组织” Express 的路由文件夹
- openstack - 使用 MicroStack 安装 OpenStack 时如何安装 cinder-volume 服务
- amazon-web-services - 为 EMR 预置的 EC2 实例添加 AWS 标记
- twilio - 从 Dialogflow(与 Twilio WhatsApp 集成)到 Twilio Flex 的移交
- asp.net - 通过 npm 安装时创建 signalr.js 文件
- api - 纽曼运行 1 个文件夹和其余的集合
- python - 试图在 jupyter notebook 中保存脚本
- excel - VBA - 函数有效,但 Excel 崩溃
- java - ES-hadoop 序列化 org.apache.hadoop.io.ShortWritable 失败
- python - t 检验中 p 值的意外分布