嘛,都是看官方文档的,就先贴上文档地址:
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