zoukankan      html  css  js  c++  java
  • Spring boot的hot swapping

    前言

    嘛,都是看官方文档的,就先贴上文档地址:
    using-boot-hot-swapping

    使用

    使用hot swapping只需要把devtools的jar包添加到你的classpath里.
    在gradle里添加依赖:

    compile("org.springframework.boot:spring-boot-devtools")
    

    然后如果你的classpath发生改变,你的application就会自动重启了.

    restart与reload

    restart

    Spring Boot提供的restart技术通过两个类加载器来工作.一个加载不会变化的class通过被加载进一个基础的类加载器,另外一些经常变化的被加载进一个restart类加载器.当应用重启时,restart类加载器会被抛弃,并且一个新的restart类加载器会被创建.意味着不变的那些class不需要再被加载一次了.

    reload

    如果restart还是不够快,或者遇到了类加载的问题,也可以用relaod的技术Spring Loaded 或者 JRebel

    排除

    有一些文件发生变化时,不需要进行重启,我们可以通过设置来排除掉他们.

    spring.devtools.restart.exclude=static/**,public/**
    

    By default changing resources in /META-INF/maven, /META-INF/resources, /resources, /static, /public or /templates will not trigger a restart but will trigger a live reload.

    添加监控的目录

    可以用spring.devtools.restart.additional-paths来添加classpath之外的需要监控变化的目录.

    禁用重启

    通过pring.devtools.restart.enabled来禁用重启的功能.
    如果要禁用restart的支持,需要在启动Spring应用前设置System的Property.

    public static void main(String[] args) {
        System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication.run(MyApp.class, args);
    }
    

    使用一个触发文件

    spring.devtools.restart.trigger-file来指定一个文件来触发重启.

    定制restart类加载器

    restart.exclude.companycommonlibs=/mycorp-common-[\w-]+.jar
    restart.include.projectcommon=/mycorp-myproj-[\w-]+.jar
    
  • 相关阅读:
    fusioncompute安装虚拟机的问题---如何扩容至5T 和 挂载Tools的解决方式
    接口请求返回状态码总结
    【内推】字节跳动
    RPA行业见解(一)
    消息中间件(一)MQ详解及四大MQ比较
    Springcloud学习
    常用加密算法
    Java实现token的生成与验证
    linux 系统下安装和卸载Node.js
    Linux安装Mysql
  • 原文地址:https://www.cnblogs.com/FJH1994/p/7645212.html
Copyright © 2011-2022 走看看