gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:41:44 24 4
gpt4 key购买 nike

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

执行 bootRun 时它构建成功,但是我的本地主机服务器未启动并导致 DEBUG CONSOLE 中出现以下异常。

Below, I've put some parts of the Debug Console.

多重绑定(bind)

> 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).

Here are the implementation statements in my build.gradle file that are relevant to what I'm doing

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

Here are a few things that I have tried to solve the problem:

我尝试将另一个 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 作为其实现。您需要从配置中删除实现“org.slf4j:slf4j-simple:1.7.21”

关于java - 如何解决 Java 和 Spring Boot 中的 slf4j logback 类路径错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55188200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com