You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot未显式依赖Apache Commons Logging,实际如何使用?

关于Spring Boot日志依赖的疑问

我在Spring Boot文档中看到:"Spring Boot使用Commons Logging处理所有内部日志..."。但在查找Spring Boot构件对Apache Commons Logging的Maven依赖时,未发现相关依赖引用。请问Spring Boot是否使用了Apache Commons Logging的独立内部分支?还是我有所遗漏?我在网上未找到太多相关信息,希望有人能提供相关指引。

以下是org.springframework.boot:spring-boot-starter-web:jar:2.7.0的依赖树:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------< dcm.dev.util:maven-dependency-resolver-tool >-------------
[INFO] Building maven-dependency-resolver-tool 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:3.2.0:tree (default-cli) @ maven-dependency-resolver-tool ---
[INFO] dcm.dev.util:maven-dependency-resolver-tool:jar:1.0
[INFO] \- org.springframework.boot:spring-boot-starter-web:jar:2.7.0:compile
[INFO]    +- org.springframework.boot:spring-boot-starter:jar:2.7.0:compile
[INFO]    |  +- org.springframework.boot:spring-boot:jar:2.7.0:compile
[INFO]    |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.7.0:compile
[INFO]    |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.7.0:compile
[INFO]    |  |  +- ch.qos.logback:logback-classic:jar:1.2.11:compile
[INFO]    |  |  |  +- ch.qos.logback:logback-core:jar:1.2.11:compile
[INFO]    |  |  |  \- org.slf4j:slf4j-api:jar:1.7.32:compile
[INFO]    |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.17.2:compile
[INFO]    |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.17.2:compile
[INFO]    |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.36:compile
[INFO]    |  +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO]    |  +- org.springframework:spring-core:jar:5.3.20:compile
[INFO]    |  |  \- org.springframework:spring-jcl:jar:5.3.20:compile
[INFO]    |  \- org.yaml:snakeyaml:jar:1.30:compile
[INFO]    +- org.springframework.boot:spring-boot-starter-json:jar:2.7.0:compile
[INFO]    |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.13.3:compile
[INFO]    |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.13.3:compile
[INFO]    |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.13.3:compile
[INFO]    |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.13.3:compile
[INFO]    |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.13.3:compile
[INFO]    |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.13.3:compile
[INFO]    +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.7.0:compile
[INFO]    |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.63:compile
[INFO]    |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.63:compile
[INFO]    |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.63:compile
[INFO]    +- org.springframework:spring-web:jar:5.3.20:compile
[INFO]    |  \- org.springframework:spring-beans:jar:5.3.20:compile
[INFO]    \- org.springframework:spring-webmvc:jar:5.3.20:compile
[INFO]       +- org.springframework:spring-aop:jar:5.3.20:compile
[INFO]       +- org.springframework:spring-context:jar:5.3.20:compile
[INFO]       \- org.springframework:spring-expression:jar:5.3.20:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:39 min
[INFO] Finished at: 2023-07-13T13:40:38-06:00
[INFO] ------------------------------------------------------------------------

解答

你没遗漏,Spring Boot并没有直接依赖Apache Commons Logging的官方包,而是使用了Spring自己维护的spring-jcl模块——也就是你依赖树里看到的org.springframework:spring-jcl:jar:5.3.20:compile。

这个spring-jcl是Spring对Commons Logging API的重实现,它保留了Commons Logging的接口规范,但内部做了适配优化:

  • 运行时会自动检测类路径下的日志实现(比如SLF4J、Log4j2等),优先使用已存在的日志框架
  • 如果没有找到其他日志实现,会自动降级使用JDK自带的JUL(java.util.logging)

Spring Boot文档里提到的"使用Commons Logging处理内部日志",指的是遵循Commons Logging的API规范,而非直接使用Apache官方的Commons Logging包。这种设计既避免了传统Commons Logging可能带来的类加载问题,同时又保持了日志API的一致性,让开发者可以灵活选择底层日志实现。


内容的提问来源于stack exchange,提问作者lmk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 13:57:00