Spring Framework 一直以来都是依赖 commons-logging,通过在 Maven pom.xml 进行配置,可以让 Spring Framework 依赖于越来越流行的 SLF4J,这是利用了 slf4j.org 提供的 jcl-over-slf4j 把 commons-logging API 转接到 SLF4J API 上实现的,这不就是移花接木吗?
1. 让 spring-context 排除对 commons-logging 的依赖
org.springframework spring-context ${spring-version} runtime commons-logging commons-logging
2. 添加 slf4j-api 和 jcl-over-slf4j 配置
org.slf4j slf4j-api ${slf4j-version} runtime org.slf4j jcl-over-slf4j ${slf4j-version} runtime org.slf4j slf4j-simple ${slf4j-version} runtime
slf4j-simple 是一个简单的 SLF4J API 实现,它直接向 System.err 输出日志内容,适用于简单应用。
补充说明:目前 Spring Framework 的最新版本是 4.0.0.RELEASE,SLF4J 的最新版本是 1.7.5。
3. SLF4J 官方的“移花接木”方案图