V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NoKey
V2EX  ›  编程

在 Springmvc 开发中 slf4j-api 1.8+ 和 log4j2 2.14 版本如何绑定

  •  
  •   NoKey · 2020-12-13 01:43:56 +08:00 · 1499 次点击
    这是一个创建于 1202 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天搭建了一个 spring mvc 工程(不是 springboot )

    在 mvnrepository 找了 slf4j 和 log4j2 的包

    把最新版本拿了下来

    pom.xml 里面按照习惯这样写的

    
        <dependency>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-core</artifactId>
          <version>2.14.0</version>
        </dependency>
    
        <dependency>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-api</artifactId>
          <version>2.14.0</version>
        </dependency>
    
        <dependency>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-slf4j-impl</artifactId>
          <version>2.14.0</version>
        </dependency>
    
    
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>2.0.0-alpha1</version>
        </dependency>
    
    
    

    运行起来有提示

    SLF4J: No SLF4J providers were found.
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#noProviders for further details.
    SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions prior to 1.8.
    SLF4J: Ignoring binding found at [jar:file:/Users/xxx/develop/code/myservice/target/myservice/WEB-INF/lib/log4j-slf4j-impl-2.14.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
    SLF4J: See http://www.slf4j.org/codes.html#ignoredBindings for an explanation.
    

    然后,我根据提示的连接进去看了一下,有个说明

    Planning for the advent of Jigsaw (Java 9), slf4j-api version 1.8.x and later use the ServiceLoader mechanism. Earlier versions of SLF4J relied on the static binder mechanism which is no longer honored by slf4j-api.
    In case SLF4J finds no providers targeting SLF4J 1.8 but finds instead bindings targeting SLF4J 1.7 or earlier, it will list the bindings it finds but otherwise ignores them.
    

    学艺不精。。。没搞懂我到底应该怎么做

    请各位大佬赐教。。。谢谢。

    2 条回复    2020-12-13 11:35:47 +08:00
    skydiver
        1
    skydiver  
       2020-12-13 02:05:01 +08:00
    NoKey
        2
    NoKey  
    OP
       2020-12-13 11:35:47 +08:00
    @skydiver 谢谢,我昨天尝试过这个包,还是有问题,可能是我启动工程有问题,今天重新启动一下就 ok 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1175 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:06 · PVG 07:06 · LAX 16:06 · JFK 19:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.