springboot 中文文档_如何通过Http远程停止SpringBoot程序(Springboot2.x)

引言

Spring Boot,作为Spring框架对“约定优先于配置(Convention Over Configuration)”理念的最佳实践的产物,它能帮助我们很快捷的创建出独立运行、产品级别的基于Spring框架的应用,大部分Spring Boot应用只需要非常少的配置就可以快速运行起来,是一个与微服务(MicroServices)相当契合的微框架。网络上关于Spring Boot的QuickStart式中文内容已经相当丰富,该文章是基于官方提供的特性,对正确地停止Spring Boot应用进行简单说明。

启用Actuator

主要通过 Http 发送 Shutdown 信号

该方式主要依赖Spring Boot Actuator的endpoint特性,具体步骤如下:

1.在pom.xml引入actuator dependency

org.springframework.boot  spring-boot-starter-actuator

application.yml配置,先打开所有端口。

management:  endpoints:    web:      exposure:        include: "*"

再查看官网,原来默认是关闭的。需要打开此配置。官方网站地址:
https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-features.html#production-ready-endpoints

management.endpoint.shutdown.enabled=true

打开之后,你可以通过 http://IP:端口号/actuator/shutdown或者http://IP:端口号/shutdown 关闭Springboot2.x的服务。

0ad78e06a9e9650ab65473e0475edc2b.png

postman执行关闭操作

安全设置

可以通过配置spirng security进行安全验证,增加密码才能完成操作。pom.xml引入

org.springframework.boot     spring-boot-starter-security

具体怎么配置才能增加密码,完成关闭的操作。可以查询相关的官方文档。这里不进行讨论了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值