[spring-projects/spring-boot]升级到 Spring Boot RC1 后应用程序有时无法启动

2024-04-29 595 views
6

升级到 Spring Boot RC1 后,我们的应用程序有时无法启动。这种情况大约发生十分之一,并出现以下错误:

2018-02-23 18:29:15.750 ERROR 1 --- [main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.ConsoleAppender[console] - Appender [console] failed to append. java.lang.NullPointerException
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:166)
        at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:82)
        at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)
        at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:115)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:263)
        at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:236)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:199)
        at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:172)
        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:127)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:351)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234)
        at eu.plumbr.probe.processing.ProbeProcessor.main(ProbeProcessor.java:42)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)

当我们重新启动它时,一切正常。发生一些比赛吗?

回答

2

我不知道这是否相关,但我们在日志中也有以下内容:

18:30:04.225 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.pattern.console' in any property source
18:30:04.230 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.pattern.file' in any property source
18:30:04.230 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.file.max-history' in any property source
18:30:04.230 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.file.max-size' in any property source
18:30:04.230 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.pattern.level' in any property source
18:30:04.231 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.pattern.dateformat' in any property source
1

@iNikem 你的应用程序有什么特别之处吗?您能够使用可以共享的示例来重现该问题吗?

3

查看历史记录 0679d4369cc99f4e26655a65398ae995fc6a36b0 或 844782b20bf1de0ca22b031fd2874a55a483044e 可能相关。

4

据我所知,没有什么特别的事情会影响日志记录。 Spring Cloud Stream 应用程序与 kafka 通信。

并且没有简单的自动取款机复制器。

2

但我们有一个自定义logback-spring.xml文件来进行基于时间的滚动:

<configuration>

    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    <include resource="org/springframework/boot/logging/logback/console-appender.xml"/>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_FILE}</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- daily rollover -->
            <fileNamePattern>${LOG_FILE}.%d{yyyyMMdd}.gz</fileNamePattern>
            <maxHistory>45</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>${FILE_LOG_PATTERN}</pattern>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="FILE"/>
    </root>
</configuration>
6

A. 运行时永远不会出现问题gradle bootRun。仅当打包并作为 Docker 容器运行时才会发生这种情况。

7

现在尝试重现我得到以下日志:

18:47:53.092 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.exception-conversion-word' in any property source
18:47:53.098 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.pattern.console' in any property source
18:47:53.096 [background-preinit] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Log4j2LoggerProvider
18:47:53.102 [background-preinit] INFO org.hibernate.validator.internal.util.Version - HV000001: Hibernate Validator 6.0.7.Final
18:47:53.106 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.pattern.file' in any property source
18:47:53.106 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.file.max-history' in any property source
18:47:53.108 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.file.max-size' in any property source
18:47:53.108 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.pattern.level' in any property source
18:47:53.109 [main] DEBUG org.springframework.core.env.PropertySourcesPropertyResolver - Could not find key 'logging.pattern.dateformat' in any property source

这是在 Spring Boot 横幅之前打印的。

3

如果我们能够获得该 NPE 的堆栈跟踪,那就太好了。看起来UnsynchronizedAppenderBase是真正捕获原始异常的类。

9

有什么建议我可以如何得到它吗?

3

您也许可以在 main 方法的 catch 块中添加类似的内容:

ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
LoggerContext context = (LoggerContext) factory;
List<Status> statuses = loggerContext.getStatusManager().getCopyOfStatusList();
for (Status status : statuses) {
    Throwable cause = status.getThrowable();
    if (cause != null) {
        cause.printStracTrace();
    }
}
7

在 Docker 容器中调试东西总是很痛苦:(

9

不,没有运气。statuses始终为空列表。

1

有什么方法可以分享您的应用程序(或其版本)以及复制问题所需的 docker 步骤吗?

5

是的,我可以共享整个 docker 映像,但是如果没有源代码,这是否有用?

但与此同时我尝试升级到 RC2。此后那些奇怪的日志就PropertySourcesPropertyResolver消失了。而且我也无法重现原来的问题:) 所以看来 RC2 解决了我的问题。我将继续测试,要么解决这个问题,要么在几天内分享该应用程序。

6

哦有趣。调试日志记录可能是#11761。我现在将关闭它,但如果您可以使用最新版本重现它,请报告。