让 Spring Framework 依赖 SLF4J 的 Maven 配置

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 的依赖

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring-version}</version>
    <scope>runtime</scope>
    <exclusions>
	<exclusion>
	    <artifactId>commons-logging</artifactId>
	    <groupId>commons-logging</groupId>
	</exclusion>
    </exclusions>
</dependency>

2. 添加 slf4j-api 和 jcl-over-slf4j 配置

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j-version}</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
    <version>${slf4j-version}</version>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>${slf4j-version}</version>
    <scope>runtime</scope>
</dependency>

slf4j-simple 是一个简单的 SLF4J API 实现,它直接向 System.err 输出日志内容,适用于简单应用。

补充说明:目前 Spring Framework 的最新版本是 4.0.0.RELEASE,SLF4J 的最新版本是 1.7.5。

3. SLF4J 官方的“移花接木”方案图

 concrete-bindings.png

转载于:https://my.oschina.net/qczhang/blog/188768

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值