问题描述
在Spring Boot文档中,他们说:每个SpringApplication都将向JVM注册一个关闭钩子,以确保ApplicationContext在退出时正常关闭."
In the Spring Boot Document, they said that 'Each SpringApplication will register a shutdown hook with the JVM to ensure that the ApplicationContext is closed gracefully on exit.'
当我在shell命令上单击ctrl+c
时,可以正常关闭该应用程序.如果我在生产机器上运行该应用程序,则必须使用以下命令java -jar ProApplicaton.jar
.但是我无法关闭shell终端,否则它将关闭进程.
When I click ctrl+c
on the shell command, the application can be shutdown gracefully. If I run the application in a production machine, I have to use the commandjava -jar ProApplicaton.jar
. But I can't close the shell terminal, otherwise it will close the process.
如果我运行nohup java -jar ProApplicaton.jar &
之类的命令,则无法使用ctrl+c
正常关闭它.
If I run command like nohup java -jar ProApplicaton.jar &
, I can't use ctrl+c
to shutdown it gracefully.
在生产环境中启动和停止Spring Boot Application的正确方法是什么?
What is the correct way to start and stop a Spring Boot Application in the production environment?
推荐答案
如果使用执行器模块,则可以通过JMX
或HTTP
如果启用了端点,则可以关闭应用程序(将endpoints.shutdown.enabled=true
添加到application.properties
文件).
If you are using the actuator module, you can shutdown the application via JMX
or HTTP
if the endpoint is enabled (add endpoints.shutdown.enabled=true
to your application.properties
file).
/shutdown
-允许正常关闭应用程序(默认情况下未启用).
/shutdown
- Allows the application to be gracefully shutdown (not enabled by default).
取决于端点公开的方式,敏感参数可以用作安全提示.例如,通过HTTP
访问敏感端点时,它们将需要用户名/密码(如果未启用Web安全,则将其禁用).
Depending on how an endpoint is exposed, the sensitive parameter may be used as a security hint. For example, sensitive endpoints will require a username/password when they are accessed over HTTP
(or simply disabled if web security is not enabled).
这篇关于如何以正确的方式关闭Spring Boot应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!