Spring Boot 實例代碼之通過接口安全退出
1、在pom.xml中引入actuator, security依賴
<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(默認(rèn)關(guān)閉)
#開啟shutdown endpoints.shutdown.enabled=true #自定義api地址 endpoints.shutdown.path=/shutdown
3、開啟密碼驗證
對/admin目錄開啟密碼驗證。
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、發(fā)送關(guān)閉HTTP請求
curl -u "admin:test" -X POST http://127.0.0.1:19888/admin/shutdown
5、返回內(nèi)容
{ "message": "Shutting down, bye..." }
總結(jié)
以上所述是小編給大家介紹的Spring Boot 實例代碼之通過接口安全退出,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
SpringBoot與rabbitmq的結(jié)合的示例
這篇文章主要介紹了SpringBoot與rabbitmq的結(jié)合的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03java生成字母數(shù)字組合的隨機(jī)數(shù)示例 java生成隨機(jī)數(shù)
這篇文章主要介紹了java生成字母數(shù)字組合的隨機(jī)數(shù)的示例,大家參考使用吧2014-01-01Spring Cloud Feign請求添加headers的實現(xiàn)方式
這篇文章主要介紹了Spring Cloud Feign請求添加headers的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-04-04IDEA整合SSM框架實現(xiàn)網(wǎng)頁上顯示數(shù)據(jù)
最近做了個小項目,該項目包在intellij idea中實現(xiàn)了ssm框架的整合以及實現(xiàn)訪問,具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-05-05