1、在pom.xml中引入actuator, security依賴
1
2
3
4
5
6
7
8
|
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> |
2、在application.properties開啟shutdown endpoint(默認關閉)
1
2
3
4
|
#開啟shutdown endpoints.shutdown.enabled= true #自定義api地址 endpoints.shutdown.path=/shutdown |
3、開啟密碼驗證
對/admin目錄開啟密碼驗證。
1
2
3
4
5
6
7
8
9
|
endpoints.shutdown.sensitive= true security.basic.enabled= true security.basic.path=/admin security.user.name=admin security.user.password=test management.security.roles=SUPERUSER management.port= 19888 management.context-path=/admin management.security.enabled= true |
4、發送關閉HTTP請求
1
|
curl -u "admin:test" -X POST http: //127.0.0.1:19888/admin/shutdown |
5、返回內容
1
2
3
|
{ "message" : "Shutting down, bye..." } |
總結
以上所述是小編給大家介紹的Spring Boot 實例代碼之通過接口安全退出,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對服務器之家網站的支持!
原文鏈接:http://blog.csdn.net/shiren513749295/article/details/77836923