Spring boot 热部署

springloader

1,在pom.xml文件创建节点并且添加依赖包:
      <build>
          <plugins>
           <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin </artifactId>
             <dependencies>  
              <!--springloaded  hot deploy -->  
              <dependency>  
                  <groupId>org.springframework</groupId>  
                  <artifactId>springloaded</artifactId>  
                  <version>1.2.4.RELEASE</version>
              </dependency>  
           </dependencies>  
           <executions>  
              <execution>  
                  <goals>  
                      <goal>repackage</goal>  
                  </goals>  
                  <configuration>  
                      <classifier>exec</classifier>  
                  </configuration>  
              </execution>  
           </executions>
             </plugin>
     </plugins>
  </build>
 
 
运行方式1,
点击项目,
run 右击,run as ==> maven build
Goals 添加sring-boot:run
可能会tomcat端口占用
 
运行方式2,run as Java Application
点击程序入口(main函数)
添加VM 配置参数,就不会占用端口
把spring-loader-1.2.4.RELEASE.jar下载下来,放到项目的lib目录中,然后把IDEA的run参数里VM参数设置为:
-javaagent:.libspringloaded-1.2.4.RELEASE.jar -noverify
 
 
springlaoder 热部署缺点:当代码修改的时候,热部署不会生效
 
springboot + devtools(热部署)
原理:底层由两个classLoader 类,一个classLoader 加载不会改变的jar包,一个classLoader去加载更改的类,成为restart classLoader,有代码更改之后,会重新启动应用。
devtools 会监视classpath 下的文件变动
 
开发工具的 build Automatically 需要打开 
 
1,pom 添加依赖
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional>
           <scope>true</scope>
</dependency> 

2,添加spring-boot-maven-plugin:<这个可以加可以不加>

<build>
  <plugins>
      <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <configuration>
             <!--fork :  如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
                 <fork>true</fork>
             </configuration>
         </plugin>
  </plugins>
</build>
 
 
 
原文地址:https://www.cnblogs.com/pickKnow/p/10496104.html