idea spring-boot-dvtools热部署要做哪些操作和配置
1.在POM配置文件中加入依赖包
<!--热部署依赖包-->
<!--Spring 官方提供的热部署插件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pagehelper-spring-boot-starter.version}</version>
</dependency>
2.开启热部署
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
3.开启idea自动make功能
按上面操作找不到就按图来:先File-Settings然后按图操作4. devtools的配置在application.yml中配置一下devtools
spring:
devtools:
restart:
enabled: true
#设置开启热部署
additional-paths: src/main/java
#重启目录
exclude: WEB-INF/** freemarker:
cache: false
#页面不加载缓存,修改即时生效
-
IDEA中配置当我们修改了类文件后,idea不会自动编译,得修改idea设置。
(1)File-Settings-Compiler-Build Project automatically
(2)ctrl + shift + alt + / ,选择Registry,勾上 Compiler autoMake allow when app running
6.设置项目启动加载方式
(1)菜单栏选择 Run->Edit Configurations…
(2)找到spring boot下的 On ‘Update’ action 和 On frame deactivation,选择 Update classes and resources
最后测试热部署,随便修改一个类中的代码,查看idea最下方的提示条,出现 build 后 紧接着 出现 parsing java… 表示正在重新编译,等待项目自动重新启动后就可以看见修改的类生效了
重点一定要在在配置文件application.properties 增加如下:logging.level.org.springframework.boot.autoconfigure: ERROR
spring.devtools.restart.poll-interval=2sspring.devtools.restart.quiet-period=1s
如果是配置文件格式是application.yml 那就创建一个properties格式的配置文件
7.如果报错清理一下缓存试试idea清理缓存的方法:File -> Invalidate Caches /Restart