当我试图在我的应用程序中使用登录时,我得到了以下错误
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和日志记录。请帮帮忙。
发布于 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
发布于 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中发生了此错误,请执行以下步骤:
发生此错误是因为logback重写了log4j2更改。因此,如果您想使用log4j2,那么您必须删除logback库和依赖项。
希望这能帮上忙。
https://stackoverflow.com/questions/48592768
复制相似问题