让 Spring Framework 依赖 SLF4J 的 Maven 配置
发布日期:2021-08-31 01:31:15 浏览次数:2 分类:技术文章

本文共 1191 字,大约阅读时间需要 3 分钟。

hot3.png

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 官方的“移花接木”方案图

 concrete-bindings.png

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

转载地址:https://blog.csdn.net/weixin_34056162/article/details/91912889 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:kafka常用命令整理
下一篇:SpringBoot JPA 自定义表名规则

发表评论

最新留言

很好
[***.229.124.182]2024年04月18日 18时11分38秒