devtools 可以方便在开发阶段 实现自动检测代码变化,自动重启,非常方便。
在springboot 中使用devtools的配置如下:
1. pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
2. 设置 idea
2.1. File ->Setting ->Build,Execution,Deployment -> Compiler
选中 Build project automatically
2.2 按 ctrl + shift + alt + / 设置 registry
3. 完成上面两部 就可实现自动重启了。。如果还需额外配置:可在application.properties 中设定
devtools 配置:
在application.properties
#热部署生效
spring.devtools.restart.enabled=true
#设置重启的目录 默认为classpath 下的。。非classpath 下的可在配置文件中手动添加
#spring.devtools.restart.additional-paths=src/main/java
#classpath目录下的WEB-INF文件夹内容修改不重启
spring.devtools.restart.exclude=WEB-INF/**
详细实现代码,参考:https://github.com/sss996/springboot-devtools