SpringBoot通过devtools实现热部署

  1. 在项目的pom.xml文件添加如下两段

  2. <dependency>  

                <groupId>org.springframework.boot</groupId>  

                <artifactId>spring-boot-devtools</artifactId>

                <version>1.5.7.RELEASE</version>

                <optional>true</optional>  

    </dependency> 

    SpringBoot通过配置devtools实现热部署

  3. <plugin>  

                    <groupId>org.springframework.boot</groupId>  

                    <artifactId>spring-boot-maven-plugin</artifactId>  

                    <configuration>  

                        <fork>true</fork>

                        <addResources>true</addResources>  

                    </configuration>  

    </plugin> 

    SpringBoot通过配置devtools实现热部署

  4. 如果使用的是Intellij IEDA开发工具,还需要到设置里将project automatically勾选上;File->Setting->Build,…->Compiler  将右侧project automatically勾上

    SpringBoot通过配置devtools实现热部署

  5. Intellij IEDA 使用ctrl+shift+a 快捷键搜索Registry,选择搜索出来的第一个

    SpringBoot通过配置devtools实现热部署

  6. 找到compiler.automake.allow.when.app.running,勾上开启此功能即可

    SpringBoot通过配置devtools实现热部署

  7. 7

    此时重新启动项目即可实现热部署,改动任意代码会立即生效,不用再每次重新启动项目

原文地址:https://www.cnblogs.com/BoKe-LY/p/11847129.html