spring-boot - 记录错误Spring Boot Gradle

标签 spring-boot logging gradle

尝试在应用程序中登录用户时出现以下错误

    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
<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的依赖
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'
}

我正在如下使用它们。
import org.apache.log4j.Logger;
@Service
public class MyService {
  Logger logger = Logger.getLogger(MyService.class.getName());

我的申请还没有开始
我尝试了谷歌搜索,但由于我是Gradle和日志记录的新手,这非常令人困惑。请帮忙。

最佳答案

您有两个实现了Logback的jar,它们正在竞争成为 Activity 的jar,正如在Caused by消息中表示的那样,这也提出了一种解决方案:remove log4j-slf4j-impl-2.6.2.jarCaused 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

关于spring-boot - 记录错误Spring Boot Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48592768/

相关文章:

json - 如何让apache以JSON而不是默认日志格式输出其日志?

windows - Gradle在Windows上规范化路径的尝试导致java.io.IOException:参数无效

bash - 作为bash脚本的一部分调用gradle会终止该脚本

spring - 不使用 spring batch + spring boot + sql server 应用程序运行 DDL 脚本

c# - 使用 Azure Bot Framework 的日志文件去了哪里?

Git pull 变更日志

android - Gradle:具有变量的项目依赖

java - 具有多个具有内部调用的微服务的蓝绿部署

spring-security - 集成 Spring Security OAuth2 和 Spring Social

java - springboot + thymeleaf 在html表格中显示数据库内容