正常关机失败 [英] Graceful shutdown fails

查看:165
本文介绍了正常关机失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 server.shutdown=graceful 的 spring boot 2.3+ 应用程序,当关闭时抛出:

I have a spring boot 2.3+ application with server.shutdown=graceful which, when getting shut down throws:

 2020-11-30 11:07:35.485  WARN 3038 --- [SpringContextShutdownHook] o.s.c.support.DefaultLifecycleProcessor  : Failed to stop bean 'webServerGracefulShutdown'
 
 java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: org/springframework/boot/web/server/GracefulShutdownResult
     at org.springframework.boot.web.servlet.context.WebServerGracefulShutdownLifecycle.stop(WebServerGracefulShutdownLifecycle.java:51)
     at org.springframework.context.support.DefaultLifecycleProcessor.doStop(DefaultLifecycleProcessor.java:238)
     at org.springframework.context.support.DefaultLifecycleProcessor.access$300(DefaultLifecycleProcessor.java:53)
     at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.stop(DefaultLifecycleProcessor.java:377)
     at org.springframework.context.support.DefaultLifecycleProcessor.stopBeans(DefaultLifecycleProcessor.java:210)
     at org.springframework.context.support.DefaultLifecycleProcessor.onClose(DefaultLifecycleProcessor.java:128)
     at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1022)
     at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:170)
     at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:949)
 Caused by: java.lang.NoClassDefFoundError: org/springframework/boot/web/server/GracefulShutdownResult
     ... 9 common frames omitted
 Caused by: java.lang.ClassNotFoundException: org.springframework.boot.web.server.GracefulShutdownResult
     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
     at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:151)
     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
     ... 9 common frames omitted
 
 2020-11-30 11:08:05.486  INFO 3038 --- [SpringContextShutdownHook] o.s.c.support.DefaultLifecycleProcessor  : Failed to shut down 1 bean with phase value 2147483647 within timeout of 30000ms: [webServerGracefulShutdown]
 2020-11-30 11:08:35.514  INFO 3038 --- [SpringContextShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
 2020-11-30 11:08:35.519  INFO 3038 --- [SpringContextShutdownHook] o.s.s.c.ThreadPoolTaskScheduler          : Shutting down ExecutorService 'taskScheduler'
 2020-11-30 11:08:35.520  INFO 3038 --- [SpringContextShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
 2020-11-30 11:08:35.528  INFO 3038 --- [SpringContextShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
 2020-11-30 11:08:35.530  INFO 3038 --- [SpringContextShutdownHook] o.s.s.c.ThreadPoolTaskScheduler          : Shutting down ExecutorService

最终应用程序关闭,但不是正常关闭,并且由于关闭是从部署脚本调用的,因此脚本失败,原因是应用程序关闭调用的退出代码 != 0.

In the end the application is shutdown, however not gracefully, and since the shutdown is being called from a deployment script, the script fails, due to the exit code != 0 of the app's shutdown call.

这可能是什么原因?我想我没有长时间运行的任务,这可能会导致这种情况,但我该如何检查?

What could be the cause of this? I think I don't have long running tasks, which can cause this, but how can I check it?

推荐答案

如果在 jar 仍在运行时替换或重命名 jar,可能会发生此问题.Java 在启动时不会将整个 jar 放在内存中,而是在需要加载某些类时使用 Jar 中类的引用.但是重命名 jar 或替换 jar 会弄乱 Jar 中的类引用.所以 java 不会在运行时找到你想要加载的类,你会看到这个 ClassNotFoundException.

This problem might happen if you replace or rename the jar while the jar is still running. Java does not take the whole jar in memory at startup and uses reference for classes in the Jar when it needs to load some classes. But renaming the jar or replacing the jar can mess up the class references inside the Jar. So java will not find the class you want to load at runtime and you will be presented with this ClassNotFoundException.

可能的解决方法: 在替换或重命名 jar 之前尝试关闭应用程序.

Possible workaround: Try to shutdown the application before replacing or renaming the jar.

这篇关于正常关机失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆