Spring Boot 實(shí)例代碼之通過接口安全退出
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、開啟密碼驗(yàn)證
對(duì)/admin目錄開啟密碼驗(yàn)證。
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請(qǐng)求
curl -u "admin:test" -X POST http://127.0.0.1:19888/admin/shutdown
5、返回內(nèi)容
{
"message": "Shutting down, bye..."
}
總結(jié)
以上所述是小編給大家介紹的Spring Boot 實(shí)例代碼之通過接口安全退出,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
SpringBoot與rabbitmq的結(jié)合的示例
這篇文章主要介紹了SpringBoot與rabbitmq的結(jié)合的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03
java生成字母數(shù)字組合的隨機(jī)數(shù)示例 java生成隨機(jī)數(shù)
這篇文章主要介紹了java生成字母數(shù)字組合的隨機(jī)數(shù)的示例,大家參考使用吧2014-01-01
Spring Cloud Feign請(qǐng)求添加headers的實(shí)現(xiàn)方式
這篇文章主要介紹了Spring Cloud Feign請(qǐng)求添加headers的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04
教你Springboot如何實(shí)現(xiàn)圖片上傳
這篇文章主要介紹了教你Springboot如何實(shí)現(xiàn)圖片上傳,首先大家明白圖片上傳,需要在數(shù)據(jù)庫定義一個(gè)varchar類型的img字段圖片字段,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07
IDEA整合SSM框架實(shí)現(xiàn)網(wǎng)頁上顯示數(shù)據(jù)
最近做了個(gè)小項(xiàng)目,該項(xiàng)目包在intellij idea中實(shí)現(xiàn)了ssm框架的整合以及實(shí)現(xiàn)訪問,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-05-05

