项目下载地址:http://download.csdn.net/detail/aqsunkai/9805821
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>
application.yml配置文件中添加:
设置WEB-INF下的jsp修改不需要重启。
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