springboot -devtools 实现热部署

阅读更多

       

              spring-boot-devtools 是一个为开发者服务的一个模块,其中最重要的功能就是自动应用代码更改到

 

最新的App上面去。原理是在发现代码有更改之后,重新启动应用,但是速度比手动停止后再启动还要更

 

快,更快指的不是节省出来的手工操作的时间。

 

其深层原理是使用了两个ClassLoader,一个Classloader加载那些不会改变的类(第三方Jar包),另一个

 

ClassLoader加载会更改的类,称为  restart ClassLoader

 

,这样在有代码更改的时候,原来的restart ClassLoader 被丢弃,重新创建一个restart ClassLoader,由于需

 

要加载的类相比较少,所以实现了较快的重启时间(5秒以内)。

 

 

第一步:

 

   添加依赖包: 

            org.springframework.boot

            spring-boot-devtools

            true

           true

 

第二步:

 

    添加spring-boot-maven-plugin:

 

   

           org.springframework.boot

           spring-boot-maven-plugin

           

         

               true

           

       

   

 

 

3.启动测试

 

 

补充:

 

  springboot-devtools实现热部署的原理:

             

          因为devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机),注意:因

 

为其采用的虚拟机机制,该项重启是很快的。

 

  springboot-devtools的页面热加载配置

 

   在application.properties 配置文件中配置spring.thymeleaf.cache=false (这里注意不同的模板配置不一样)

 

 

  转载

 

        http://412887952-qq-com.iteye.com/

你可能感兴趣的:(热加载)