利用SpringBoot提供的监控管理组件进行关闭
SpringBoot提供了准生产环境下的应用监控和管理功能,我们可以通过HTTP,JMX,SSH协议来进行操作,自动得到审计、健康及指标信息等。
导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
设置SpringBoot优雅关闭
management:
endpoints:
web:
exposure:
include: shutdown
endpoint:
shutdown:
enabled: true
shutdown端点默认是关闭的,这样配置好后我们就能通过POST请求【ip:端口/api/shutdown】这个URL来关闭SpringBoot应用了。