欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作

一:啟動時完成數(shù)據(jù)加載等需求

成都創(chuàng)新互聯(lián)從2013年成立,先為劍河等服務(wù)建站,劍河等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為劍河企業(yè)網(wǎng)站制作PC+手機+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

實現(xiàn)ApplicationListener接口,官方文檔截圖:

詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作

ApplicationListener接口的泛型類可以使用ApplicationStartedEvent和ApplicationReadyEvent

詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作

應(yīng)用監(jiān)聽器事件執(zhí)行先后順序如下:

  1. ApplicationStartingEvent
  2. ApplicationEnvironmentPreparedEvent
  3. ApplicationPreparedEvent
  4. ApplicationStartedEvent
  5. ApplicationReadyEvent
  6. ApplicationFailedEvent

實現(xiàn)CommandLineRunner和ApplicationRunner完成啟動加載數(shù)據(jù)

詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作

詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作

二:關(guān)閉時完成某些操作

實現(xiàn)ApplicationListener<ContextClosedEvent>

實現(xiàn)DisposableBean接口 

詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作

三、spring boot應(yīng)用關(guān)閉操作(Linux/unix/ubuntu環(huán)境下進(jìn)行)

A、非安全驗證

1、項目pom.xml添加如下依賴包:

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

2、application.properties文件添加如下內(nèi)容:

#啟用shutdownendpoints.shutdown.enabled=true#禁用密碼驗證endpoints.shutdown.sensitive=false

3、關(guān)閉命令:

curl -X POST host:port/shutdown

B、安全驗證

1、pom.xml添加如下依賴包:

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

2、application.properties文件添加以下內(nèi)容:

#開啟shutdown的安全驗證endpoints.shutdown.sensitive=true
#驗證用戶名security.user.name=admin
#驗證密碼security.user.password=admin
#角色management.security.role=SUPERUSER
# 指定端口management.port=8081
# 指定地址management.address=127.0.0.1

3、關(guān)閉命令:

curl -u admin:admin -X POST http://127.0.0.1:8081/manage/shutdown

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

分享題目:詳解Springboot應(yīng)用啟動以及關(guān)閉時完成某些操作
網(wǎng)頁地址:http://chinadenli.net/article0/jhpoio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司面包屑導(dǎo)航營銷型網(wǎng)站建設(shè)云服務(wù)器外貿(mào)網(wǎng)站建設(shè)網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)