一.熱部署java
在開發中咱們修改一個Java文件後想看到效果不得不重啓應用,這致使大量時間花費,咱們不但願重啓應用的狀況下,程序能夠自動部署(熱部署)。git
1.1 模板引擎github
在SpringBoot中開發狀況下禁用模板引擎的cache,頁面模板改變ctrl+F9能夠從新編譯當前頁面並生效。redis
1.2 Spring Loadedspring
Spring官方提供的熱部署程序,實現修改類文件的熱部署,須要下載Spring Loaded(項目地址),使用時須要添加運行時參數:-javaagent:C:/springloaded-1.2.5.RELEASE.jar-noverifyeclipse
1.3 JRebelide
收費的一個熱部署軟件,安裝插件使用。spring-boot
1.4 Spring Boot Devtools(推薦)post
引入依賴,使用IDEA的編譯或者ctrl+f9,若是用eclipse使用保存即ctrl+s便可實現熱部署。ui
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
二.監控管理
經過引入spring-boot-starter-actuator,可使用Spring Boot爲咱們提供的準生產環境下的應用監控和管理功能。咱們能夠經過HTTP、JMX,SSH協議來進行操做,自動獲得審計、健康及指標信息等。
因爲SpringBoot2.x版本在這一塊有所變更因此須要將SpringBoot版本切換爲1.5.x版本,防止版本問題影響。
2.1 引入spring-boot-starter-actuator
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2.2 經過http方式訪問監控端點
監控和管理端點:
2.3 可進行shutdown(POST提交,此端點默認關閉)
能夠經過發送"/shutdown"post請求來關閉應用。
2.3.1 開啓shutdown關閉應用
endpoints.shutdown.enabled=true
2.3.2 使用postman發送post請求
2.4 定製端點信息
定製端點通常經過endpoints+端點名+屬性名來設置。
修改端點id(endpoints.beans.id=mybeans),這樣設置之後訪問beans端點就須要訪問"/mybeans"了
修改端點訪問路徑(endpoints.beans.path=beans)
開啓遠程應用關閉功能(endpoints.shutdown.enabled=true)
開啓關閉端點(endpoints.beans.enabled=false)
關閉全部端點訪問(endpoints.enabled=false)
修改根路徑方法(management.context-path=/manage)
修改訪問端點的端口(management.port=8181)
2.5 自定義HealthIndicator
訪問/health端口,能夠看到應用監控的監控情況。例如redis鏈接是否正常,若是鏈接地址不正確致使鏈接不上redis地址,健康狀態就會顯示down。那麼如何自定義一個健康狀態指示器呢?
首先,編寫一個指示器 實現HealthIndicator接口,而且指示器的名字須要命名爲xxxHealthIndicator並加入容器中。
@Component public class MyHealthIndicator implements HealthIndicator { @Override public Health health() { //自定義檢查方法 // return Health.up().build(); return Health.down().withDetail("msg","服務異常").build(); } }
所有編寫好後,重啓項目訪問"/health"就能夠查看該指示器了。