【问题标题】:Logback upgrade from 1.1.11 to 1.3.0-alpha4 in Spring boot-1.5.8 application在 Spring boot-1.5.8 应用程序中从 1.1.11 升级到 1.3.0-alpha4
【发布时间】:2019-04-18 12:02:38
【问题描述】:

Spring boot 1.5.8 默认提供 logback-1.1.11 版本。 我正在尝试将 logback 版本从 1.1.11 升级到 1.3.0-alpha4 并在 pom 中添加以下两个属性。

<slf4j.version>1.8.0-beta4</slf4j.version>
<logback.version>1.3.0-alpha4</logback.version>

当我尝试运行应用程序时出现以下异常。

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:273)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:98)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:230)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:209)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
    at org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:69)
    at org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:48)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:292)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at com.anthem.acmp.service.UMIDALServiceApplication.main(UMIDALServiceApplication.java:25)
Caused by: java.lang.ClassNotFoundException: org.slf4j.impl.StaticLoggerBinder
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 14 more

我发现 logback-classic-1.1.11.jar 包含一个包 org.slf4j.impl,它具有类 StaticLoggerBinder,它在 logback-classic-1.3.0-alpha4 中不可用并导致此问题。

【问题讨论】:

  • 正如依赖项已经提到的那样,这些是软件的 beta 和 alpha 版本。您通常不想用于生产的东西。 Spring Boot 在构建时考虑了 SLF4J 1.7 而不是 1.8。因此,您可能会遇到兼容性问题。

标签: java spring-boot logback spring-logback logback-classic


【解决方案1】:

与 1.2 和 1.7 版本相比,Logback 1.3 和 SLF4J 1.8 包含破坏性 API 更改。在撰写本文时,Spring Boot 与新 API 不兼容。有一个issue 正在跟踪对新版本的支持。在项目稳定下来并且不再处于 alpha 或 beta 阶段之前,它不会得到解决。

【讨论】:

    【解决方案2】:

    当我将StaticLoggerBinder from version 1.2 复制到我的项目中时,我能够使用 logback 1.3.0-alpha4。 (在新包org.slf4j.impl 中创建一个新的StaticLoggerBinder.java 并粘贴整个文件。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 2022-12-22
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多