繁体   English   中英

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

[英]How would I resolve an slf4j logback classpath error in Java and Spring Boot?

因此,我目前正在使用Twilio发送和接收短信。 我将Spring Boot用于应用程序的框架,将Gradle作为构建工具,将VSCode作为IDE。

在执行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会产生一个构建错误,并说这些软件包不存在

我还尝试阅读DEBUG CONSOLE的URL: http : //www.slf4j.org/codes.html#multiple_bindings ,但我发现对于Gradle没什么用,因为解决方案仅适用于Maven

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM