zoukankan      html  css  js  c++  java
  • SpringBoot 04_热部署

    热部署应用环境

    IDEA2017.2 + MAVEN3.5 + SpringBoot1.5.6


    热部署说明

    1. devtools会监听classpath下的文件变动,并且会立即重启应用(发生在保存时机),注意:因为其采用的虚拟机机制,该项重启是很快的。

    2. devtools可以实现页面热部署(即页面修改后会立即生效,这个可以直接在application.properties文件中配置spring.thymeleaf.cache=false来实现(这里注意不同的模板配置不一样)

    • 条件一:添加Maven依赖
    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <version>1.5.6.RELEASE</version>
    </dependency>


    • 条件二:添加spring-boot-maven-plugin插件
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
            <!--fork :  如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
            <fork>true</fork>
        </configuration>
    </plugin>
    • 条件三:idea开启自动编译项目

    CTRL + SHIFT + A --> make project automatically --> 点击进入 –> 打勾



    image

    image


    • 条件四:IDEA开启自动编译在程序运行时

    CTRL + SHIFT + A --> 查找Registry --> 找到compiler.automake.allow.when.app.running   --> 勾选

    image

    image

    • 条件5:重启IDEA,验证

    启动项目:

    image

    访问接口:http:localhost:8080/devtool/hello

    @RestController
    @RequestMapping("/devtool")
    public class DevTollController {
    
        @GetMapping("/hello")
        public String hello(){
            return "hello";
        }
    }

    image

    此时能够访问成功,若此时新增一个接口,在没有手动重启服务的情况下依旧能够访问的话则说明发生了热部署

    @RestController
    @RequestMapping("/devtool")
    public class DevTollController {
    
        @GetMapping("/hello")
        public String hello(){
            return "hello";
        }
    
        @GetMapping("hello2")
        public String hello2(){
            return "hello2";
        }
    
    }

    image


    image

    如果实现了热部署,就再也不用浪费时间在部署上了,可以随心所欲的写代码了。

    出了上述的测试方式,你还可以这样测试:

    •修改类-->保存:应用会重启

    •修改配置文件-->保存:应用会重启

    •修改页面-->保存:应用会重启,页面会刷新(原理是将spring.thymeleaf.cache设为false)

  • 相关阅读:
    Velocity 创建命令缓存
    关于RESTful Web Services和RESTful设计的一些文章
    [转]Restful Web Services浅析
    Silverlight点滴(四)Silverlight访问Web Service报"System.Security.SecurityException: 安全性错误"的处理
    WebDevHelper RESTful服务和Ajax开发时的利器
    [原]读Google Data API源代码一:从创建一个日历(Calendar)开始
    [转]使用 WCF 和 .NET Framework 3.5 进行 HTTP 编程
    [原]Silverlight3 支持所有HTTP方法
    [原]RESTful Web Service之以HTTP PUT方式调用WCF服务
    [原]Google API学习2:Google API稍深入一步
  • 原文地址:https://www.cnblogs.com/homeword/p/7441209.html
Copyright © 2011-2022 走看看