我认为 spring-boot-starter-security 中的某些模块与 log4j 冲突,但我不知道是哪个。
我的gradle依赖如下:
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security"){
exclude module: "spring-boot-starter-logging"
}
compile "org.apache.logging.log4j:log4j-api"
compile "org.apache.logging.log4j:log4j-core"
compile "org.apache.logging.log4j:log4j-slf4j-impl"
compile('org.apache.poi:poi:3.10.1')
compile('org.apache.poi:poi-ooxml:3.10.1')
testCompile("junit:junit")
maven 的解决方案相同:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.1.RELEASE</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
我的问题继续是:删除 Logback 或从 log4j-slf4j-impl-2.12.0.jar 加载的竞争实现类 org.apache.logging.slf4j.Log4jLoggerFactory
我添加了
configurations {
all {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
exclude group: 'ch.qos.logback', module: 'logback-classic'
exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'
}
}
到我的 gradle.build 并用最新版本刷新了所有项目依赖项并解决了问题。
我明白了
compile("org.springframework.boot:spring-boot-starter-security"){
exclude module: "spring-boot-starter-logging"
exclude module: "logback-classic"
}
compile("org.springframework.boot:spring-boot-starter-thymeleaf"){
exclude module: "logback-classic"
}
使用IDEA“显示依赖关系”或
mvn dependency:tree -Dverbose
找到所有logback-classic jar文件,并排除它们。
包含后开始看到此错误
'it.ozimov:embedded-redis:0.7.3'
我必须更改
testImplementation 'it.ozimov:embedded-redis:0.7.3'
到
testImplementation ('it.ozimov:embedded-redis:0.7.3') {
exclude module: 'commons-logging'
exclude module: 'slf4j-simple'
}
问题已解决。
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
对我来说,这就是解决方案,因为 OpenAPI Generator 带来了这个,并且它与 SpringsBoot 默认值冲突。 所以一旦我排除了这个,SpringBootApp 就开始工作了。
对我来说,这个问题仅在执行 maven-surefire-plugin 期间出现。不知何故,Logback 存在于类路径中,即使它没有添加到项目依赖项中。我添加了这样的修复:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<systemPropertyVariables>
<org.springframework.boot.logging.LoggingSystem>
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
</org.springframework.boot.logging.LoggingSystem>
</systemPropertyVariables>
</configuration>
</plugin>
您也可以使用
mvn clean install -Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.log4j2.Log4J2LoggingSystem
根据此文档,Spring Boot 由于 Web Starter 自动配置 Log Back 库。您应该排除 spring-boot-starter-logging 来解决该问题。
要排除 gradle 项目上的默认 LogBack 配置,
configurations {
all*.exclude module : 'spring-boot-starter-logging'
all*.exclude module : 'logback-classic'
}
根据 这个 bug,捆绑且不可删除的 Kotlin 插件(提醒我强制将 U2 专辑包含在 iOS 中)包括
org.gradle.kotlin.kotlin-dsl
,这反过来又会用不兼容的日志库(即使禁用)污染类路径。
我通过将首选项中的运行程序从“IntelliJ IDEA”更改为“Gradle”解决了这个问题:
对我有用:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- avoid: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. on run with vscode -->
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
根据@Bohemian 的帖子:
删除这个对我来说解决了:
plugins {
`kotlin-dsl`
}
错误参考来自@Bohemian
建议将这个插件添加到 kotlin dsl 的 gradle 文件中,但我发现它确实不需要......语法突出显示之后仍然对我有用,删除它后我没有看到任何问题。事实上,它删除了该线程中提到的问题以将其删除。
我可以编辑 stanalone.xml 文件,并在日志中进行相关操作,按住 Ctrl 键并删除所有礼仪和列表。
应该告诉你的是,在尝试排除我发现的每个对我不起作用的 logback 工件后,我刚刚删除了 maven 文件夹(/.m2)。又一个之后
mvn clean install
一切开始都很好,错误再也没有出现。顺便说一下,我删除了之前所做的所有排除。还在工作