我的应用程序将部署在tcServer和WebSphere 6.1上。此应用程序使用ehCache,因此需要slf4j作为依赖项。 结果我将slf4j-api.jar(1.6)jar添加到我的war文件包中。
除了以下错误之外,应用程序在tcServer中正常工作:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
但是,当我在WebSphere中部署时,我得到java.lang.NoClassDefFoundError: org.slf4j.impl.StaticLoggerBinder
。
我检查了两个应用程序服务器的类路径,但没有其他的slf4j jar。
有没有人有任何想法可能会发生在这里?
答案 0 :(得分:431)
我在WebSphere 6.1中遇到了同样的问题。正如Ceki指出的那样,WebSphere正在使用大量的罐子,其中一个指向旧版本的slf4j。
No-Op回滚只发生在slf4j -1.6+上,所以任何比这更旧的东西都会抛出异常并停止部署。
SLf4J site中有一个解决此问题的文档。我跟着它,并将slf4j-simple-1.6.1.jar
添加到我的应用程序以及我已经拥有的slf4j-api-1.6.1.jar
。
这解决了我的问题。希望它可以帮助那些有这个问题的人。
答案 1 :(得分:291)
这适用于那些从谷歌搜索来到这里的人。
如果你使用maven,只需添加以下内容
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
或
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
</dependency>
答案 2 :(得分:40)
您需要在类路径中添加以下jar文件:slf4j-simple-1.6.2.jar
。如果您没有,请下载。请参阅http://www.slf4j.org/codes.html#multiple_bindings
答案 3 :(得分:33)
只需将其添加到 pom.xml :
即可<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
答案 4 :(得分:23)
这里有一些答案建议将slf4j-simple依赖项添加到你的maven pom文件中。您可能想要检查最新版本。
https://mvnrepository.com/artifact/org.slf4j/slf4j-simple 您将找到最新版本的SLF4J Simple Binding。选择最适合你的那个(从2017-03开始1.7.25仍是2019-03的稳定版本)并将其包含在你的pom.xml中。
2019年2月的测试版
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.8.0-beta4</version>
<scope>test</scope>
</dependency>
稳定版
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
答案 5 :(得分:21)
我遇到了同样的错误。我在本地开发中配置了slf4j-api,slf4j-log4j12和log4j。所有配置都很好,但我从mvnrepository复制的slf4j-log4j12依赖项有测试范围<scope>test</scope>
。当我删除它时,每件事都很好。
有时候愚蠢的错误会打破我们的脑袋;)
答案 6 :(得分:18)
有时我们应该看到警告中的注释,例如。 SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
。
您可以搜索此警告的原因
将*slf4j-nop.jar
,slf4j-simple.jar
,slf4j-log4j12.jar
,slf4j-jdk14.jar
或logback-classic.jar*
中的一个jar添加到类路径中可以解决问题。
compile "org.slf4j:slf4j-api:1.6.1"
compile "org.slf4j:slf4j-simple:1.6.1"
例如,将上述代码添加到build.gradle
或将相应代码添加到pom.xml
以用于maven项目。
答案 7 :(得分:14)
将文件slf4j-log4j12-1.6.4.jar
放入类路径中就可以了。
答案 8 :(得分:10)
如果您正在使用maven进行依赖关系管理,那么您只需在pom.xml中添加以下依赖项
即可<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
对于非Maven用户 只需下载库并将其放入项目类路径中即可。
您可以在此处查看详细信息:http://www.mkyong.com/wicket/java-lang-classnotfoundexception-org-slf4j-impl-staticloggerbinder/
答案 9 :(得分:8)
SLF4j是各种日志框架的抽象。因此,除了拥有slf4j之外,您还需要在类路径中包含任何日志框架,如log4j或logback(etc)。
要有一个想法,请参考http://logback.qos.ch/manual/introduction.html
答案 10 :(得分:5)
Slf4j是底层日志框架的外观,如log4j,logback,java.util.logging。
要与底层框架连接,slf4j使用绑定。
如果错过了绑定jar,则抛出上述错误。您可以下载此jar并将其添加到classpath。
对于maven依赖,
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
除了slf4j-log4j12-1.7.21.jar之外,它还会将slf4j-api-1.7.21.jar以及log4j-1.2.17.jar拉入你的项目
答案 11 :(得分:5)
我遇到了使用Java 9库的Spring-boot-2应用程序的类似问题。
在我的pom.xml中添加以下依赖项为我解决了这个问题:
<dependency>
<groupId>com.googlecode.slf4j-maven-plugin-log</groupId>
<artifactId>slf4j-maven-plugin-log</artifactId>
<version>1.0.0</version>
</dependency>
答案 12 :(得分:4)
当我收到以下错误时,我遇到了这个问题:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
我在slf4j-api-1.7.5.jar
中使用libs
。
尽管我尝试了整个建议的补充广告,例如slf4j-log4j12-1.7.5.jar
,slf4j-simple-1.7.5
,但错误消息仍然存在。当我将slf4j-jdk14-1.7.5.jar
添加到java libs时,问题终于得到了解决。
答案 13 :(得分:4)
在Websphere案例中,您有一个旧版本的slf4j-api.jar,1.4.x。或1.5.x位于某处。您在tcServer上观察到的行为,即故障转移到NOP,发生在slf4j版本1.6.0及更高版本上。确保在所有平台上使用slf4j-api-1.6.x.jar,并且没有在类路径上放置旧版本的slf4j-api。
答案 14 :(得分:4)
请将以下依赖项添加到pom以解决此问题。
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
答案 15 :(得分:3)
我在Struts2 + Spring项目中工作。所以它需要一个依赖slf4j-api-1.7.5.jar
。
如果我运行该项目,我会收到类似
的错误无法加载类“org.slf4j.impl.StaticLoggerBinder”
我通过添加slf4j-log4j12-1.7.5.jar
解决了我的问题。
因此,在项目中添加此jar以解决问题。
答案 16 :(得分:3)
如SLF4J Manual所述
Java的简单日志记录外观(SLF4J)作为简单外观 或各种日志框架的抽象,例如 java.util.logging,logback和log4j。
和
将绑定添加到类路径后,警告将消失。
因此,您应该选择要使用的绑定。
NoOp绑定(slf4j-nop)
绑定为NOP,静默丢弃所有日志记录。
通过https://search.maven.org/search?q=g:org.slf4j%20AND%20a:slf4j-nop&core=gav检查新版本
简单绑定(slf4j-simple)
将所有事件输出到System.err。仅打印INFO或更高级别的消息。这种绑定在小型应用程序的环境中可能有用。
通过https://search.maven.org/search?q=g:org.slf4j%20AND%20a:slf4j-simple&core=gav检查新版本
日志框架的绑定(java.util.logging,logback,log4j)
如果要将日志写入文件,则需要这些绑定之一。
请参见https://www.slf4j.org/manual.html#projectDep
的描述和说明。我的意见
我建议 Logback ,因为它是 log4j 项目的后续版本。
在https://search.maven.org/search?q=g:ch.qos.logback%20AND%20a:logback-classic&core=gav上查看绑定的最新版本
您可以立即获得控制台输出,但如果需要将日志写入文件,只需将FileAppender
配置放在src/main/resources/logback.xml
或src/test/resources/logback-test.xml
上,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>logs/logs.log</file>
<encoder>
<pattern>%date %level [%thread] %logger{10} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
<logger level="DEBUG" name="com.myapp"/>
</configuration>
(请参见手册中的详细说明:https://logback.qos.ch/manual/configuration.html)
答案 17 :(得分:2)
作为jar包含和纯maven解决方案的替代方法,您可以将其包含在from maven和gradle中。
1.7.25
// https://mvnrepository.com/artifact/org.slf4j/slf4j-simple
api group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.25'
将其放在build.gradle
文件的依赖项中。
答案 18 :(得分:2)
我添加了此依赖项来解决此问题:
https://mvnrepository.com/artifact/org.slf4j/slf4j-simple/1.7.25
答案 19 :(得分:2)
这可以使用相同的版本解决。我试过了并解决了
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
答案 20 :(得分:1)
我解决了添加这个库的问题:slf4j-simple-1.7.25.jar 您可以在官方网站https://www.slf4j.org/download.html
下载此内容答案 21 :(得分:1)
根据SLF4J官方文档
无法加载类org.slf4j.impl.StaticLoggerBinder
此时会报告此警告消息 无法加载org.slf4j.impl.StaticLoggerBinder类 记忆。当找不到合适的SLF4J绑定时会发生这种情况 在班级路径上。 放置一个(只有一个) 的slf4j-nop.jar, slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或 类路径上的logback-classic.jar应该可以解决问题。
只需将this jar和slf4j api.jar一起添加到您的类路径即可完成任务。 祝你好运
答案 22 :(得分:1)
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
将上述依赖项放在pom.xml文件中
答案 23 :(得分:1)
根据SLF4J错误代码
无法加载类org.slf4j.impl.StaticLoggerBinder 当org.slf4j.impl.StaticLoggerBinder类无法加载到内存中时,将报告此警告消息。当在类路径上找不到合适的SLF4J绑定时,就会发生这种情况。将slf4j-nop.jar slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或logback-classic.jar中的一个(仅一个)放置在类路径上即可解决此问题。
请注意,slf4j-api版本2.0.x和更高版本使用ServiceLoader机制。面向slf4j-api 2.x的后端(如logback 1.3和更高版本)不随org.slf4j.impl.StaticLoggerBinder一起提供。如果放置针对slf4j-api 2.0.x的日志记录后端,则需要在类路径上使用slf4j-api-2.x.jar。另请参见relevant faq条目。
SINCE 1.6.0 从SLF4J 1.6版开始,在没有绑定的情况下,SLF4J将默认为无操作(NOP)记录器实现。
如果您负责打包应用程序并且不关心日志记录,那么将slf4j-nop.jar放在应用程序的类路径中将摆脱此警告消息。请注意,诸如库或框架之类的嵌入式组件不应声明对任何SLF4J绑定的依赖,而只能依赖slf4j-api。当库声明对SLF4J绑定的编译时依赖性时,它会将绑定强加给最终用户,从而否定了SLF4J的目的。
答案 24 :(得分:0)
解决方案在其官方网站上显示:
无法加载类org.slf4j.impl.StaticLoggerBinder
此时会报告此警告消息 无法加载org.slf4j.impl.StaticLoggerBinder类 记忆。当找不到合适的SLF4J绑定时会发生这种情况 在班级路径上。放置一个(也是唯一一个)slf4j-nop.jar slf4j-simple.jar,slf4j-log4j12.jar,slf4j-jdk14.jar或 类路径上的logback-classic.jar应该可以解决问题。以来 1.6.0从SLF4J版本1.6开始,在没有绑定的情况下,SLF4J将默认为无操作(NOP)记录器实现。如果你是 负责包装应用程序而不关心 记录,然后将slf4j-nop.jar放在你的类路径上 应用程序将摆脱此警告消息。注意嵌入式 库或框架等组件不应声明 依赖于任何SLF4J绑定但仅依赖于slf4j-api。当一个 库声明了对SLF4J绑定的编译时依赖性 强加给最终用户的绑定,从而否定了SLF4J的目的。
解决方案:我已经在intellij上使用maven研究添加到我的项目中,并选择了slf4j-jdk14.jar。
答案 25 :(得分:0)
我使用Jena并将同伴依赖添加到pom.xml
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
我尝试添加slf4j-simple但它只是消失了“SLF4J:无法加载类”org.slf4j.impl.StaticLoggerBinder“”错误但logback-classic显示更多详细信息。
答案 26 :(得分:0)
最可能您的问题是由于@thangaraj引起的<scope>test</scope>
(在某些情况下也是<scope>provided</scope>
)造成的。
此范围表示正常情况下不需要依赖项 使用该应用程序,并且仅可用于测试编译 和执行阶段。 Test dependencies aren’t transitive and are only present for test and execution classpaths.
因此,如果您不需要依赖来进行测试,则可以使用代替(在mvnrepository中将看到的内容):
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.24</version>
<scope>test</scope>
</dependency>
没有任何作用域(如果未提供其他作用域,则默认为 compile scope ):
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
</dependency>
这与:
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
<scope>compile</scope>
</dependency>
答案 27 :(得分:0)
这是我的5美分...
运行测试时,我遇到了同样的问题。因此,我通过添加仅针对测试运行时的实现来解决此问题。我正在为此项目使用gradle。
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
testRuntimeOnly组:“ ch.qos.logback”,名称:“ logback-classic”, 版本:“ 1.2.3”
答案 28 :(得分:0)
对我来说,问题是: 使用Hibernate,我发现它已经使用了slf4j,并且已经在我的类路径中,因此我决定使用它。 下一步-为slf4j添加imlementor,因此我将其添加到了maven:
fun RecyclerView.pageSnap() = this.post {
if (this.onFlingListener == null) PagerSnapHelper().attachToRecyclerView(this)
}
fun RecyclerView.snapCenterWithMargin(left: Int, top: Int, right: Int, bottom: Int) {
val offsetItemDecoration = SnapCenterWithMargin(left, top, right, bottom)
this.addItemDecoration(offsetItemDecoration)
}
private class SnapCenterWithMargin(
private val left: Int,
private val top: Int,
private val right: Int,
private val bottom: Int
) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
view.measure(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)
val position = parent.getChildAdapterPosition(view)
val firstItem = 0
val lastItem = state.itemCount - 1
when (position) {
firstItem -> {
val firstPadding = (parent.width) / 2 - view.measuredWidth / 2
outRect.set(firstPadding, 0, 0, 0)
}
lastItem -> {
val lastPadding = (parent.width) / 2 - view.measuredWidth / 2
outRect.set(0, 0, lastPadding, 0)
}
else -> {
outRect.set(left, top, right, bottom)
}
}
}
}
但是失败并显示错误! SLF4J:无法加载类“ org.slf4j.impl.StaticLoggerBinder”
解决方案是: Hibernate对slf4j的依赖性为版本 1.7.26 ,我添加了次要版本依赖性 1.7.25 。因此,当我解决此问题后,一切都OK了
答案 29 :(得分:0)
在payara 5.191上遇到了相同的问题
jcl-over-slf4j和slf4j-log4j12一起解决了这个问题
<properties>
<slf4j.version>1.7.29</slf4j.version>
</properties>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
答案 30 :(得分:0)
我没有添加任何依赖关系,只是改变了使用它们的方式。
(如果您使用的是弹性搜索版本<7.0,请取消注释此代码)
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: portal-ingress-home
namespace: portal
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
#nginx.ingress.kubernetes.io/rewrite-target: /$2
ingress.kubernetes.io/whitelist-source-range: "213.#####9/20"
spec:
tls:
- hosts:
- portal
secretName: portal-tls
rules:
- host: portal
- http:
paths:
- path: /
backend:
serviceName: customer
servicePort: 80
- path: /cust(/|$)(.*)
backend:
serviceName: customer
servicePort: 80
IndexRequest indexRequest = new IndexRequest(
"twitter",
"tweets",
id // this is to make our consumer idempotent
).source(record.value(), XContentType.JSON);
我正在使用bulkrequest,因此我删除了该错误。
答案 31 :(得分:0)
我知道这篇文章有点旧,但万一有其他人遇到这个问题:
将slf4j-jdk14-X.X.X.jar添加到您的CLASSPATH(其中X.X.X是版本号 - 例如slf4j-jdk14-1.7.5.jar)。
HTH 彼得