IntelliJ IDEA 作为当下较为热门的Java IDE,当使用Spring Boot进行开发时,由于静态页面经常修改,每次重启十分麻烦。因此实现Spring Boot热部署尤为重要。
Devtools
Spring为开发者提供了spring-boot-devtools模块进行Spring Boot热部署,提高了开发效率,无需手动重启应用。使用需要在pom.xml添加如下配置:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<addResources>true</addResources>
</configuration>
</plugin>
在application.yml中添加配置
thymeleaf:
cache: false # 关闭cache,刷新即可显示新页面
devtools: restart:
enabled: true # 启用热部署
additional-paths: src/main/resources # 设置重启目录
IDEA设置
(1)File->Settings->Compiler->Build project automatically,将其打勾。
(2)ctrl+shift+A,在检索框输入Registry,随后找到Compiler autoMake allow when app running,勾选。
重启应用,此时不论是修改java文件还是修改html文件都会自动重新加载。
本文详细介绍如何使用spring-boot-devtools模块实现SpringBoot项目的热部署,包括pom.xml配置、application.yml配置以及IDEA设置,让代码修改即时生效,大幅提升开发效率。
5127

被折叠的 条评论
为什么被折叠?



