Spring Boot 整合 Log4j2 不起作用
Spring Boot Log4j2 大约 1415 字现象
pom
文件中引入了log4j2
。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.6.0</version>
</dependency>
启动项目时提示使用了logback
。
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/maven/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/maven/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.13.3/log4j-slf4j-impl-2.13.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
原因
因为项目是web
项目,所以引入了spring-boot-starter-web
,但spring-boot-starter-web
包括了spring-boot-starter-logging
依赖,而spring-boot-starter-logging
里面包含了logback
的依赖导致了此问题。
解决
将spring-boot-starter-logging
排除即可。
重新打包启动无提示报错。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
阅读 1941 · 发布于 2021-12-13
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Linux 查看 cron 定时任务执行日志阅读 6103
-
PHP 设置 json_encode 不转义中文阅读 2051
-
MySQL server has gone away阅读 2329
-
软考大纲:系统架构设计师阅读 1179
-
Android 监听 SIM 卡状态阅读 5450
-
start.spring.io 无法访问解决办法阅读 6158
-
Redis 使用 hash tag 插入到同一个哈希槽阅读 5265
-
Spring 组件的注册时机阅读 1362
-
Java 中类的变量、代码块、构造方法加载的顺序阅读 1497
-
Spring Boot 使用 Jib 打包成 Docker 镜像阅读 627