如何解决Java和Spring Boot中的slf4j logback类路径错误?

詹姆士

所以我目前正在使用Twilio发送和接收短信。我使用Spring Boot的是应用程序框架,Gradle构建工具和VSCodeIDE。

执行时它可以成功生成bootRun,但是我的本地服务器无法启动,并导致下列异常DEBUG CONSOLE

在下面,我放置了调试控制台的某些部分。

多重绑定

> Task :bootRun
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/james/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.21/be4b3c560a37e69b6c58278116740db28832232c/slf4j-simple-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/james/.gradle/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.2.3/7c4f3c474fb2c041d8028740440937705ebb473a/logback-classic-1.2.3.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.SimpleLoggerFactory]

Java IllegialArgumentException

Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory loaded from file:/C:/Users/james/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.21/be4b3c560a37e69b6c58278116740db28832232c/slf4j-simple-1.7.21.jar).

这是我build.gradle文件中与我正在做的事情有关的实现语句

implementation 'org.slf4j:slf4j-simple:1.7.21'
implementation 'com.sparkjava:spark-core:2.7.1'
implementation 'com.twilio.sdk:twilio:7.17.+'

这是我尝试解决问题的一些方法:

我试图将以下内容从另一个StackOverflow问题放到我的gradle文件中

configurations.all {
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
    exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    exclude group: 'org.springframework.boot', module: 'logback-classic'
    exclude group: "org.slf4j"
}

此时运行bootRun将产生一个构建错误,并指出这些软件包不存在

我还尝试阅读以下网址中的URL DEBUG CONSOLEhttp : //www.slf4j.org/codes.html#multiple_bindings,但我发现没有任何有用的方法Gradle,因为解决方案仅用于Maven

在这一点上,我不确定该怎么办。

有任何想法吗?提前致谢。

凯达·乔希

Spring Boot本身依赖于SLF4J和Logback作为其实现。您需要implementation 'org.slf4j:slf4j-simple:1.7.21'从配置中删除

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Slf4j和类路径错误

类路径包含多个SLF4J绑定Spring Boot排除问题

如何修复 WebLogic 部署中的 slf4j 错误

SLF4J:类路径包含多个SLF4J绑定Spring Maven

如何解决此错误:java.lang.NoClassDefFoundError:org / slf4j / impl / StaticLoggerBinder?

无法运行Spring Maven项目,如何解决Class路径包含多个SLF4J绑定?

将Spring示例应用程序部署到Cloud Foundry时出现“ SLF4J:类路径包含多个SLF4J绑定”错误

Websphere多个slf4j logback绑定可以解决

Spring Boot SLF4j登录

如何在保留SLF4J的同时从库的依赖项中删除logback?

SLF4J和Logback的依赖性管理

如何使slf4j / logback在控制台上打印?

没有jcl-over-slf4j的Spring + Logback(slf4j)日志记录

Java,Maven:构建期间出现SLF4J错误

在Play 2.3.x启动时如何修复“ SLF4J:类路径包含多个SLF4J绑定”?

如何使用Spring Boot / slf4j在日志文件的名称中包含日期?

什么是log4j的,SLF4J和的logback之间的区别?

区别log4j,slf4j和logback

如何在java spring中将slf4j与多个类一起使用?

类路径包含多个SLF4J绑定,log back-classic和log4j

@Service 中的 Spring Boot slf4j 记录器未记录

Spring,SLF4J和Logback-自定义数据库追加器

如何使用Slf4j的Logback实现使用Spring记录肥皂客户端消息

slf4j未能绑定记录器,尽管在类路径上存在logback

使用 SLF4J 和 Logback 创建日志文件的问题

使用logback和slf4j记录休眠参数值

SLF4J和Logback:将记录器传播到自动连接的服务

为什么Slf4j / Logback日志文件名和行号不

Spring SLF4J记录器的构造函数注入-如何获取注入目标类?