嘛,都是看官方文檔的,就先貼上文檔地址:
using-boot-hot-swappinghtml
使用hot swapping只須要把devtools的jar包添加到你的classpath裏.
在gradle裏添加依賴:git
compile("org.springframework.boot:spring-boot-devtools")
而後若是你的classpath發生改變,你的application就會自動重啓了.github
Spring Boot提供的restart技術經過兩個類加載器來工做.一個加載不會變化的class經過被加載進一個基礎的類加載器,另一些常常變化的被加載進一個restart類加載器.當應用重啓時,restart類加載器會被拋棄,而且一個新的restart類加載器會被建立.意味着不變的那些class不須要再被加載一次了.spring
若是restart仍是不夠快,或者遇到了類加載的問題,也能夠用relaod的技術Spring Loaded 或者 JRebelapp
有一些文件發生變化時,不須要進行重啓,咱們能夠經過設置來排除掉他們.maven
spring.devtools.restart.exclude=static/**,public/**
By default changing resources in
/META-INF/maven
,/META-INF/resources
,/resources
,/static
,/public
or/templates
will not trigger a restart but will trigger a live reload.spring-boot
能夠用spring.devtools.restart.additional-paths
來添加classpath以外的須要監控變化的目錄.gradle
經過pring.devtools.restart.enabled
來禁用重啓的功能.
若是要禁用restart的支持,須要在啓動Spring應用前設置System的Property.spa
public static void main(String[] args) { System.setProperty("spring.devtools.restart.enabled", "false"); SpringApplication.run(MyApp.class, args); }
用spring.devtools.restart.trigger-file
來指定一個文件來觸發重啓.rest
restart.exclude.companycommonlibs=/mycorp-common-[\\w-]+\.jar restart.include.projectcommon=/mycorp-myproj-[\\w-]+\.jar