尝试在应用程序中登录用户时出现以下错误
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.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
关于spring-boot - 记录错误Spring Boot Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48592768/