SpringBoot学习:使用spring-boot-devtools进行热部署
pom.xml添加依赖:
- <!--支持热启动jar包-->
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-devtools</artifactId>
- <version>${spring-boot.version}</version>
- <optional>true</optional>
- <!-- optional=true,依赖不会传递,该项目依赖devtools;之后依赖该项目的项目如果想要使用devtools,需要重新引入 -->
- </dependency>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <fork>true</fork>
- </configuration>
- <dependencies>
- <!-- spring热部署-->
- <!-- https://mvnrepository.com/artifact/org.springframework/springloaded -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>springloaded</artifactId>
- <version>1.2.6.RELEASE</version>
- </dependency>
- </dependencies>
- </plugin>
- spring:
- devtools:
- restart:
- #热部署生效
- enabled: true
- #设置重启的目录
- #additional-paths: src/main/java
- #classpath目录下的WEB-INF文件夹内容修改不重启
- exclude: WEB-INF/**
当我们修改了java类后,IDEA默认是不自动编译的,而spring-boot-devtools又是监测classpath下的文件发生变化才会重启应用,所以需要设置IDEA的自动编译:
(1)File-Settings-Compiler-Build Project automatically
(2)ctrl + shift + alt + /,选择Registry,勾上 Compiler autoMake allow when app running