java 如何摆脱“类路径包含多个 SLF4J 绑定”警告?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14837429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get rid of the "Class path contains multiple SLF4J bindings" warning?
提问by user706838
This is more-or-less a "common" question, however, I haven't managed to find a good answer yet. So, again, here is the warning:
这或多或少是一个“常见”问题,但是,我还没有找到一个好的答案。所以,再一次,这里是警告:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/eualin/.m2/repository/org/slf4j/slf4j-jcl/1.6.0/slf4j-jcl-1.6.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/eualin/.m2/repository/org/slf4j/slf4j-log4j12/1.5.11/slf4j-log4j12-1.5.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
And here are two potential solutions to the problem [1][2].
Assuming that they will both work for me, obviously, they are just hacks, and I am not sure if I should rely on any of them at all. What would you recommend me? Keep in mind that the warning does not appear when in terminal; only when I run the application through IntelliJIDEA.
假设它们都对我有用,很明显,它们只是黑客,我不确定我是否应该依赖它们中的任何一个。你会推荐我什么?请记住,在终端中不会出现警告;只有当我通过 IntelliJIDEA 运行应用程序时。
Any suggestion is highly appreciated.
任何建议都受到高度赞赏。
采纳答案by Snapman
SLF4J expects only one version of StaticLoggerBinder to be present in any application runtime. If there is more than one, SLF4J cannot guarantee that log messages will be routed to the appropriate logger.
SLF4J 期望在任何应用程序运行时中只存在一个版本的 StaticLoggerBinder。如果有多个,SLF4J 不能保证日志消息将被路由到适当的记录器。
The architecture of SLF4J requires that only one library be used to route log messages (e.g. slf4j-<logging framework>.jar
). When multiple classpath's are in play via application servers, IDE's, startup scripts, etc., SLF4J libraries can get included multiple times. You may have to hunt and peck to find where classpath's are either being added or modified in IntelliJIDEA (such as in the configured Java compilers or in any startup configurations).
SLF4J 的架构要求只使用一个库来路由日志消息(例如slf4j-<logging framework>.jar
)。当多个类路径通过应用程序服务器、IDE、启动脚本等运行时,SLF4J 库可以被多次包含。您可能需要寻找和寻找类路径在 IntelliJIDEA 中添加或修改的位置(例如在配置的 Java 编译器或任何启动配置中)。
回答by Stephen C
It is presumably happening because IntelliJIDEA is adding one of those slf4j binding JARs itself. My guess is happening when you run unit tests. So one approach would see if you can exclude the other JAR in the launcher configs for the the Unit test runner.
这可能是因为 IntelliJIDEA 正在添加那些 slf4j 绑定 JAR 本身之一。我的猜测是在您运行单元测试时发生。因此,一种方法是查看是否可以在单元测试运行器的启动器配置中排除其他 JAR。
But at the end of the day, this warning is harmless, and you could simply ignore it.
但归根结底,此警告是无害的,您可以直接忽略它。
回答by Contango
In my particular case, I got this error in IntelliJ IDEA
, and refreshing Gradle fixed this error:
在我的特殊情况下,我在 中遇到了这个错误IntelliJ IDEA
,刷新 Gradle 修复了这个错误:
You can find this window from View..Tool Windows..Gradle
.
您可以从 中找到此窗口View..Tool Windows..Gradle
。
Our setup is:
我们的设置是:
- IntelliJ IDEA v15
- Gradle
- Jenkins
- SVN
- IntelliJ IDEA v15
- 摇篮
- 詹金斯
- SVN
回答by Mad Calm
In project's POM-file, set needed logging backend be default in the list of found deps by adding to your project a direct dependency on it, for example :
在项目的 POM 文件中,通过向项目添加对它的直接依赖,将所需的日志后端设置为默认值,例如:
<groupid>ch.qos.logback</groupid>
<artifactid>logback-classic</artifactid>
<scope>runtime</scope>
</dependency>```