美文网首页
Springboot中logback与slf4j冲突排坑

Springboot中logback与slf4j冲突排坑

作者: 超巨大的门牙 | 来源:发表于2020-03-23 22:07 被阅读0次

之前下了ruoyi的脚手架来做开发,因为项目需要,把整个工程拆成了前后端分离的形式。
由于项目中使用了zookeeper作为服务治理,导致在用Junit进行单元测试时出现了logback与slf4j冲突的问题。

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.slf4j.impl.Log4jLoggerFactory loaded from file:/C:/Users/lys/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.Log4jLoggerFactory
    at org.springframework.util.Assert.instanceCheckFailed(Assert.java:655)
    at org.springframework.util.Assert.isInstanceOf(Assert.java:555)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:286)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:102)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:220)
    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:199)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
    at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
    at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
    at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
    ... 24 more

springboot使用logback打印日志,我们的项目正好用了这一点,所以解决办法是排除掉zookeeper中slf4j的依赖

<dependency>
  <groupId>org.apache.dubbo</groupId>
  <artifactId>dubbo-dependencies-zookeeper</artifactId>
  <type>pom</type>
  <exclusions>
    <exclusion>
      <artifactId>slf4j-log4j12</artifactId>
      <groupId>org.slf4j</groupId>
    </exclusion>
  </exclusions>
</dependency>

相关文章

  • Springboot中logback与slf4j冲突排坑

    之前下了ruoyi的脚手架来做开发,因为项目需要,把整个工程拆成了前后端分离的形式。由于项目中使用了zookeep...

  • 第15章 SpringBoot集成logging日志

    第15章 SpringBoot集成logging日志 15.1 SLF4J与Logback简介 15.2 spri...

  • springBoot与日志

    springboot默认使用slf4j和logback,springboot能够适配所以框架,但是我们引用其他框架...

  • 配置文件logback-spring.xml

    logback文件基本信息 SpringBoot工程自带logback和slf4j的依赖,所以重点放在编写配置文件...

  • SpringBoot日志配置

    SpringBoot日志类库默认采用Slf4j,日志系统采用Logback 1.新建项目,在pom.xml中引入 ...

  • SpringBoot日志

    springboot使用SLF4J+logback的组合 使用SLF4J各种组合需要导入的jar SLF4J是一个...

  • springboot内置logback

    logback和slf4j的关系 刚开始接触日志,公司一般都采用springboot中去整合slf4j和logba...

  • Logback的使用与配置

    Logback的使用与配置 1.Logback的基本使用 使用@Slf4j注解简化书写: 依赖: 代码: 注意:如...

  • 2018-03-08 关于spring-boot logback

    以下是一个简单的xml日志记录模板 注意事项: springboot的日志系统是slf4j和logback组成,基...

  • logback日志配置

    实现了门面日志@slf4j,其配置大同小异,logback、log4j2基本差不太多,以下看springboot默...

网友评论

      本文标题:Springboot中logback与slf4j冲突排坑

      本文链接:https://www.haomeiwen.com/subject/quoyyhtx.html