spring-boot热部署可以当修改了class之后自动重启项目,方便调试。在pom.xml中添加
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
在plugin中添加fork
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--fork : 如果没有该项配置,肯定devtools不会起作用,即应用不会restart -->
<fork>true</fork>
</configuration>
</plugin>
配置后后可以自动重启。
但debug时发现,第一次启动会莫名进入SilentExitExceptionHandler.exitCurrentThread方法。看日志发现线程名从main变成了restartedMain,应该是此处引起线程退出,自己没有打断点,无法取消。百度一下,Eclipse有配置:window->【Preferences】->【Java】->【Debug】:去掉【Suspend execution on uncaught exceptions】前面的勾。
11:38:46.080 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/E:/workspace/nidap-logservice/target/classes/, file:/C:/workspace/pine-sql/target/classes/]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.0.1.RELEASE)
2018-08-02 11:38:46.988 INFO 31872 --- [ restartedMain] c.t.n.logservice.LogServiceApplication : Starting LogServiceApplication on DESKTOP-U8R517O with PID 31872 (E:\workspace\nidap-logservice\target\classes started by admin in E:\workspace\nidap-logservice)