1、添加maven依赖,不需要指定版本,spring boot 会自动添加对应的版本
<!-- 热部署 -->
<!-- devtools可以实现页面热部署(即页面修改后会立即生效,
这个可以直接在application.properties文件中配置spring.thymeleaf.cache=false来实现) -->
<!-- 实现类文件热部署(类文件修改后不会立即生效),实现对属性文件的热部署。 -->
<!-- 即devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机),
注意:因为其采用的虚拟机机制,该项重启是很快的 -->
<!-- (1)base classloader (Base类加载器):加载不改变的Class,例如:第三方提供的jar包。 -->
<!-- (2)restart classloader(Restart类加载器):加载正在开发的Class。 -->
<!-- 为什么重启很快,因为重启的时候只是加载了在开发的Class,没有重新加载第三方的jar包。 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<!-- optional=true, 依赖不会传递, 该项目依赖devtools;
之后依赖boot项目的项目如果想要使用devtools, 需要重新引入 -->
<optional>true</optional>
</dependency>
2、添加配置,application.properties或application.yml
properties文件
#热部署生效
spring.devtools.restart.enabled=true
#设置重启的目录,添加需要restart的目录
spring.devtools.restart.additional-paths=src/main/java
# 为mybaties设置,生产环境可删除
restart.include.mapper=/mapper-[\\w-\\.]+jar
restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
#排除不需要restart的目录
#spring.devtools.restart.exclude=static/**,public/**
#classpath下的web-inf的内容修改不需要restart
#spring.devtools.restart.exclude=WEB-INF/**
yml文件
spring:
profiles:
active: spring.active@
mvc:
static-path-pattern: /static/**
view:
prefix: /WEB-INF/view
devtools:
restart:
enabled: true
additional-paths: src/main/java
exclude: static/**,WEB-INF/view/**
注意:IDEA需要开启自动编译