Spring Boot启动slf4j提示找不到weblogic.xml日志异常

简介: Spring Boot启动slf4j提示找不到weblogic.xml日志异常

启动Spring Boot项目时,会遇到如下关于slf4j相关的日志异常情况,导致项目无法启动。

相关异常信息如下:

Exception in thread "main" 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:~/.m2/repository/org/slf4j/slf4j-log4j12/1.7.30/slf4j-log4j12-1.7.30.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:696)
  at org.springframework.util.Assert.isInstanceOf(Assert.java:596)

很明显项目中并没有用到所谓的weblogic.xml,那么怎么会报关于WEB-INF/weblogic.xml配置的异常呢?


其中关键新增在这里:


LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation……

1

就是说Logback已经在classpath中存在,但LoggerFactory并不是Logback的相关日志上线文内容。此时就应该意识到有Logback依赖冲突。


此时,可用过查看maven依赖来排查问题,在项目跟目录执行如下命令:


mvn dependency:tree

1

展示结果内容如下:


[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.3.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.3.3.RELEASE:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.1.5:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.1.5:compile
[INFO] |  |  +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO] |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.5:compile
[INFO] |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.5:compile
[INFO] |  +- org.springframework:spring-core:jar:4.2.5.RELEASE:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.16:compile
...
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.5:compile

很显然,可以看出多处引用了同样的slf4j-api的jar包。也就是jar包冲突了,此时将依赖的jar包排除掉,只有一处即可。

如果是springboot中的jar包无效可使用如下方式排除:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

如果是其他依赖库的jar包无效则可通过同样的方式排除:

<dependency>
  <groupId>com.github.secbr</groupId>
  <artifactId>fastdfs-client-plus</artifactId>
  <version>1.1.1-RELEASE</version>
  <exclusions>
    <exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
  </exclusions>
</dependency>

然后再重新启动springboot项目,项目便可正常启动。


相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
27天前
|
Java 应用服务中间件 Maven
SpringBoot 项目瘦身指南
SpringBoot 项目瘦身指南
41 0
|
2月前
|
XML Java 数据格式
Spring IoC容器初始化过程(xml形式)
Spring IoC容器初始化过程(xml形式)
46 0
|
7天前
|
安全 Java 应用服务中间件
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
24 0
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
|
9天前
|
XML Java C++
【Spring系列】Sping VS Sping Boot区别与联系
【4月更文挑战第2天】Spring系列第一课:Spring Boot 能力介绍及简单实践
【Spring系列】Sping VS Sping Boot区别与联系
|
1月前
|
网络安全
ssh(Spring+Spring mvc+hibernate)——applicationContext.xml
ssh(Spring+Spring mvc+hibernate)——applicationContext.xml
7 0
|
1月前
|
前端开发 Java 数据安全/隐私保护
Spring Boot3自定义异常及全局异常捕获
Spring Boot3自定义异常及全局异常捕获
45 1
|
2月前
|
应用服务中间件
weblogic配置、修改日志保存目录、配置滚动日志
weblogic配置、修改日志保存目录、配置滚动日志
|
2月前
|
XML 监控 druid
【Java专题_02】springboot+mybatis+pagehelper分页插件+druid数据源详细教程
【Java专题_02】springboot+mybatis+pagehelper分页插件+druid数据源详细教程
|
2月前
|
XML Java 测试技术
【SpringBoot】基于 Maven 的 pom.xml 配置详解
【SpringBoot】基于 Maven 的 pom.xml 配置详解
224 0
【SpringBoot】基于 Maven 的 pom.xml 配置详解
|
2月前
log4j2.xml的日志打印配置
log4j2.xml的日志打印配置
30 0