为什么要实现热部署
当我们在写项目时,每一次我们修改代码的时候就得重新启动项目,重新部署,这个就很烦而且相当的浪费时间,这时候热部署的出现都很舒服了。
如何配置
- 首先pom.xml中添加依赖和插件 - 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29- <dependencies> 
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
 </dependency>
 <!--devtools热部署-->
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-devtools</artifactId>
 <optional>true</optional>
 <scope>true</scope>
 </dependency>
 </dependencies>
 <build>
 <plugins>
 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 <configuration>
 <fork>true</fork>
 </configuration>
 </plugin>
 </plugins>
 </build>- 在application.yaml中配置一下 - 1 
 2
 3
 4
 5
 6
 7
 8- spring: 
 devtools:
 restart:
 enabled: true #设置开启热部署
 additional-paths: src/main/java #重启目录
 exclude: WEB-INF/**
 freemarker:
 cache: false #页面不加载缓存,修改即时生效- application.properties配置方式 - 1 
 2- #配置项目热部署 
 spring.devtools.restart.enabled=true- 当我们修改了类文件后,idea不会自己编译,还需要修改idea设置 - File-Settings-Compiler-Build Project automatically
- ctrl + shift + alt + / ,选择Registry,勾上 Compiler autoMake allow when app running
 - 好了这样我们的热部署就完成了 - 修改类–>保存:应用会重启
- 修改配置文件–>保存:应用会重启
- 修改页面–>保存:应用不会重启,但会重新加载,页面会刷新
 - 这样我们修改代码就不用重新启动项目了,这不是美滋滋了。 
 
          
          
          
         
          
         
          
        