正常关机失败
Graceful shutdown fails
我有一个 spring boot 2.3+ 应用程序 server.shutdown=graceful,它在关闭时抛出:
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.access0(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.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。
这可能是什么原因造成的?我想我没有很长的 运行 任务,这可能会导致这种情况,但我该如何检查呢?
如果在 jar 仍然 运行 时替换或重命名 jar,则可能会发生此问题。 Java 不会在启动时将整个 jar 放在内存中,而是在需要加载一些 classes 时使用 Jar 中的 classes 的引用。但是重命名 jar 或替换 jar 可能会弄乱 Jar 中的 class 引用。因此 java 将找不到您要在运行时加载的 class,您将看到此 ClassNotFoundException
.
Possible workaround:
在替换或重命名 jar 之前尝试关闭应用程序。
我们在 git 实验室管道中遇到了同样的问题,我已将管道更改为先停止现有应用程序,然后替换新的 jar 文件。希望这会解决问题。
我有一个 spring boot 2.3+ 应用程序 server.shutdown=graceful,它在关闭时抛出:
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.access0(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.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。
这可能是什么原因造成的?我想我没有很长的 运行 任务,这可能会导致这种情况,但我该如何检查呢?
如果在 jar 仍然 运行 时替换或重命名 jar,则可能会发生此问题。 Java 不会在启动时将整个 jar 放在内存中,而是在需要加载一些 classes 时使用 Jar 中的 classes 的引用。但是重命名 jar 或替换 jar 可能会弄乱 Jar 中的 class 引用。因此 java 将找不到您要在运行时加载的 class,您将看到此 ClassNotFoundException
.
Possible workaround:
在替换或重命名 jar 之前尝试关闭应用程序。
我们在 git 实验室管道中遇到了同样的问题,我已将管道更改为先停止现有应用程序,然后替换新的 jar 文件。希望这会解决问题。