java - 如何解决 Java 和 Spring Boot 中的 slf4j logback 类路径错误?
问题描述
所以我目前正在使用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 IllegalArgumentException
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
:http ://www.slf4j.org/codes.html#multiple_bindings ,但没有发现任何有用的Gradle
的解决方案,因为解决方案仅适用于Maven
.
在这一点上,我不确定还能做什么。
有任何想法吗?提前致谢。
解决方案
Spring Boot 本身依赖于 SLF4J 和 Logback 作为其实现。您需要implementation 'org.slf4j:slf4j-simple:1.7.21'
从配置中删除。
推荐阅读
- generics - 如果您只有一个 KClass 对象,那么用具体的类型参数调用一个有趣的东西?
- linux - 在 debian 9 上安装 docker
- bash - Gnuplot 使用 bash 二维数组
- kubernetes - Kubernetes 中 Pod 的资源分配
- php - 使用 PHP 回显完整 json 的编码段
- java - 一次处理两个相邻元素的集合(使用流)
- python - 如何使用管道在子进程之间正确传递信息?
- ios - Firebase 未在 Swift / iOS 中显示 microsoft.com 的登录页面
- azure-devops - 在 Azure DevOps 中自动化多个构建/发布
- optaplanner - 如何在 VehicleRouting 示例中实现 Constraint Match Total