首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >日志记录错误弹簧启动级

日志记录错误弹簧启动级
EN

Stack Overflow用户
提问于 2018-02-03 00:32:26
回答 2查看 1.4K关注 0票数 0

当我试图在我的应用程序中使用登录时,我得到了以下错误

代码语言:javascript
复制
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:58)
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.apache.logging.slf4j.Log4jLoggerFactory loaded from jar:file:/home/dev/code/my_proj/build/libs/proj-core-0.1.0.jar!/BOOT-INF/lib/log4j-slf4j-impl-2.6.2.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.apache.logging.slf4j.Log4jLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext
        at org.springframework.util.Assert.isInstanceOf(Assert.java:346)
        at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartedEvent(LoggingApplicationListener.java:226)
        at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:205)
        at org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:62)
        at org.springframework.boot.SpringApplicationRunListeners.started(SpringApplicationRunListeners.java:48)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
        at com.abc.def.Application.main(Application.java:22)
        ... 8 more

这是我的logback.xml

代码语言:javascript
复制
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">

        <encoder>
            <pattern>%date{YYYY-MM-dd HH:mm:ss} [%.7thread] %level %logger{10}:%line %mdc%n %msg%n</pattern>
        </encoder>


    </appender>

    <logger name="com.abc" level="debug"
            additivity="false">
        <appender-ref ref="STDOUT"/>
    </logger>
    <root level="ERROR">
        <appender-ref ref="STDOUT"/>
    </root>
</configuration>

这是我在build.gradle中的依赖项

代码语言:javascript
复制
dependencies {
    compile("org.springframework.boot:spring-boot-starter-data-mongodb")
    compile ('org.springframework.boot:spring-boot-starter-web'){
        exclude module: 'org.springframework.boot:spring-boot-starter-logging'
    }
    compile ('org.springframework.boot:spring-boot-starter-log4j2')
    compile("org.springframework.boot:spring-boot-starter-actuator")
    compile("org.springframework.boot:spring-boot-starter-mail")
    compile("org.springframework.boot:spring-boot-starter-amqp")
    testCompile("org.springframework.boot:spring-boot-starter-test")
    compile group: 'org.springframework', name: 'spring-context-support'

    compile 'org.codehaus.groovy:groovy'
}

我正在使用它们如下。

代码语言:javascript
复制
import org.apache.log4j.Logger;
@Service
public class MyService {
  Logger logger = Logger.getLogger(MyService.class.getName());

我的应用程序甚至还没有开始,我尝试了谷歌搜索,但它非常混乱,因为我是新的Gradle和日志记录。请帮帮忙。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-02-03 12:25:29

您有两个带有Logback实现的jars,它们正在竞争成为活动的jars,正如在提示解决方案的by消息中所表达的那样:删除log4j-slf4j-impl-2.6.2.jar

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.apache.logging.slf4j.Log4jLoggerFactory loaded from jar:file:/home/dev/code/my_proj/build/libs/proj-core-0.1.0.jar!/BOOT-INF/lib/log4j-slf4j-impl-2.6.2.jar!/). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml Object of class [org.apache.logging.slf4j.Log4jLoggerFactory] must be an instance of class ch.qos.logback.classic.LoggerContext

票数 0
EN

Stack Overflow用户

发布于 2019-03-15 09:55:20

原因: java.lang.IllegalArgumentException: LoggerFactory不是一个Logback LoggerContext,但是Logback在类路径上。删除Logback或竞争实现(从jar:file:/home/dev/code/my_proj/build/libs/proj-core-0.1.0.jar!/BOOT-INF/lib/log4j-slf4j-impl-2.6.2.jar!/).加载类org.apache.logging.slf4j.Log4jLoggerFactory )如果您正在使用WebLogic,您将需要在WEB/weblogic.xml类的org.apache.logging.slf4j.Log4jLoggerFactory对象中添加“org.slf4j”以更好地选择-application-packages,类org.apache.logging.slf4j.Log4jLoggerFactory的对象必须是类ch.qos.logback.classic.LoggerContext的实例。

如果在尝试使用SpringBoot时在log4j2中发生了此错误,请执行以下步骤:

  • 通过添加"excludeGroupIds log4j-slf4j-impl /excludeGroupIds“将jar从包装时删除。
  • 使用命令"mvn tree:tree“找出哪个库依赖于”logback-经典“。
  • 无论您在哪里找到它,都会将它从依赖项中排除在外。

发生此错误是因为logback重写了log4j2更改。因此,如果您想使用log4j2,那么您必须删除logback库和依赖项。

希望这能帮上忙。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48592768

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档