關閉Spring Boot應用程序,咱們能夠經過OS命令kill -9 進程ID 實現將進程殺死。可是,有沒有一種更好的方式,好比經過REST請求實現?Spring Boot Actoator提供了實現。經過提供的shutdown服務能夠實現安全的關閉Spring Boot應用。簡單實用步驟以下:spring
step1:pom引入spring boot Actoator依賴:安全
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>服務器
step2:開啓shutdown endpoint,默認是關閉的,須要在
appapplication.properties
中開啓shutdown endpoint
:
curl
spring-boot
post
經過上面的設置便可實現關閉spring boot應用,可是你會發現,這樣會十分不安全,只要經過服務調用便可關閉應用,因此,具體應用中經常須要進行安全認證,好比藉助Spring boot security,步驟以下:url
step1:pom.xml添加security依賴spa
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
step2:開啓安全驗證,application.properties
中變動配置:code
security.user.password=password #密碼
management.security.role=XX_ROLE#角色
step3:指定路徑、IP、端口
endpoints.shutdown.path=/custompath #指定shutdown的路徑,若是須要統一指定應用的路徑,則能夠用management.context-path=/manage
management.port=XXX #指定管理端口
management.address=X.X.X.X #指定客戶端ID