springboot 停止

本文介绍如何在Spring Boot应用中配置服务的安全关闭机制。通过设置特定的端点和安全认证,可以在不影响应用运行的情况下优雅地关闭服务。文章还提供了具体的配置示例。

因springboot内嵌tomcat或jetty使得我们没法去操作服务:

因此,常常是服务起来后,要重启时会端口占用,我们只能无情的kill掉端口。

不过spring也设置有配置停止的请求:

Application.properties中添加:

endpoints.shutdown.enabled=true
endpoints.shutdown.sensitive=false

在pom.xml中添加:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

此时,需要停止服务时,只需要在网页上以post的形式请求:

  http://ip:port/shutdown

也可通过控制台:

>curl -X POST http://127.0.0.1:8081/shutdown

 最后结果为: {"message":"Shutting down, bye..."}

以上的停止方式不安全,会导致任何人都可以进行操作。因此需要添加安全限制。

endpoints.shutdown.enabled=true
endpoints.shutdown.sensitive=true
endpoints.shutdown.path=shutdown
security.user.name=root
security.user.password=denny#2018
management.security.role=SUPERUSER
management.context-path=/manage
#management.port=8080
#management.address=192.168.204.21

在pom.xml中添加security的服务:

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

 

转载于:https://www.cnblogs.com/DennyZhao/p/9407475.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值