springboot怎么停止服务器?

如题所述

可以以通过HTTP发送shutdown信号的方式停止服务器。

具体步骤如下:

1. 在pom.xml中引入actuator依赖

<dependency>   

<groupId>org.springframework.boot</groupId> 

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

2.开启shutdown endpoint

Spring Boot Actuator的shutdown endpoint默认是关闭的,因此在application.properties中开启shutdown endpoint:

#启用shutdownendpoints.shutdown.enabled=true

#禁用密码验证endpoints.shutdown.sensitive=false

3. 发送shutdown信号

shutdown的默认url为host:port/shutdown,当需要停止服务时,向服务器post该请求即可,如:curl -X POST host:port/shutdown
将得到形如{"message":"Shutting down, bye..."}的响应

4. 安全设置

开启安全验证
在application.properties中变更配置,并

#开启shutdown的安全验证

endpoints.shutdown.sensitive=true

#验证用户名security.user.name=admin

#验证密码security.user.password=secret

#角色management.security.role=SUPERUSER

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网