既然所有的传递依赖项都已经存在于log42j -boot-starter-web中,为什么我们还需要为spring添加额外的依赖项呢?从我可以在互联网上读到的任何教程中,每个人都提到了添加依赖性:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
他们还提到将spring-boot-starter-logging
排除在spring-boot-starter-web
之外。
<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>
但是为什么我们需要这样做呢?我看到spring-boot-starter-log4j2
中的所有依赖项都已经存在于spring-boot-starter-logging
中。
发布于 2020-07-06 00:37:27
日志记录的默认依赖项不是log4j,而是logback。如果您删除了依赖项,那么理想情况下,您应该不能在项目中使用log4j导入。你能检查一下这个吗?log4j依赖项仅在依赖项管理中声明,但您需要包含该依赖项才能使用此声明的依赖项。
参考:https://docs.spring.io/spring-boot/docs/2.0.x/reference/html/howto-logging.html
发布于 2020-07-09 13:52:27
Spring默认的日志记录是由Apache支持的Logback支持的。因此,如果您想在系统中提供日志记录,可以使用logback来实现。现在,如果您提出了针对logback的排除问题,这只是为了让spring知道您正在使用不同的日志记录框架。
发布于 2021-02-07 18:08:57
当包含spring-boot-starter-logging
时:
org.springframework.boot:spring-boot-starter-logging:jar:2.4.2:compile
+- ch.qos.logback:logback-classic:jar:1.2.3:compile
| +- ch.qos.logback:logback-core:jar:1.2.3:compile
| \- org.slf4j:slf4j-api:jar:1.7.30:compile
+- org.apache.logging.log4j:log4j-to-slf4j:jar:2.13.3:compile
| \- org.apache.logging.log4j:log4j-api:jar:2.13.3:compile
\- org.slf4j:jul-to-slf4j:jar:1.7.30:compile
,则log4j-core
不存在。
另一方面,当包含spring-boot-starter-log4j2
时:
org.springframework.boot:spring-boot-starter-log4j2:jar:2.4.2:compile
+- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.13.3:compile
| +- org.slf4j:slf4j-api:jar:1.7.30:compile
| \- org.apache.logging.log4j:log4j-api:jar:2.13.3:compile
+- org.apache.logging.log4j:log4j-core:jar:2.13.3:compile
+- org.apache.logging.log4j:log4j-jul:jar:2.13.3:compile
\- org.slf4j:jul-to-slf4j:jar:1.7.30:compile
,那么它就存在了。
https://stackoverflow.com/questions/62644834
复制相似问题