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

    什么是java热部署?
    当修改代码之后,会重新编译代码生成class文件
    热部署就是检测到class文件有变化时自动重启应用

    SpringBoot热部署有两种方式

    1、使用spring loaded
    2、使用spring-boot-devtools

    1 spring loaded

    这种是使用mvn spring-boot:run方式启动的,如果是从Application run里面直接运行,则绕开了maven插件,热部署无法生效
    gradle的配置方式:

    dependencies {
        implementation("org.springframework:springloaded:1.2.5.RELEASE")
    }

    这种方式验证不生效,不知道什么原因

    2 spring-boot-devtools
    这种方式无论怎么启动,热部署都可以生效
    gradle的配置方式:

    dependencies {
        implementation("org.springframework.boot:spring-boot-devtools")
    }

    注意事项:
    1、如果发现没有热部署效果,则需要检查IDE配置中有没有打开自动编译

    2、如果使用Thymeleaf模板引擎,需要把模板默认缓存设置为false

    # 禁止thymeleaf缓存(建议:开发环境设置为false,生成环境设置为true)
    spring.thymeleaf.cache=false

    3、针对devtools的可以指定目录或者排除目录来进行热部署

    #添加那个目录的文件需要restart
    spring.devtools.restart.additional-paths=src/main/java
    #排除那个目录的文件不需要restart
    spring.devtools.restart.exclude=static/**,public/**

    4、默认情况下,/META-INF/maven,/META-INF/resources,/resources,/static,/templates,/public这些文件夹下的文件修改不会使应用重启,但是会重新加载(devtools内嵌了一个LiveReload Server,当资源发生改变时,浏览器刷新)

    5、在application.properties中配置spring.devtools.restart.enabled=false,此时restart类加载器还会初始化,但不会监视文件更新。在SprintApplication.run之前调用System.setProperty(“spring.devtools.restart.enabled”, “false”);可以完全关闭重启支持。

  • 相关阅读:
    flutter 布局
    常见错误
    xpath
    bzoj1485 [HNOI2009]有趣的数列 卡特兰数
    博弈 Nim问题 POJ2234
    bzoj 1014 [JSOI2008]火星人prefix
    codevs 1743 反转卡片 rope or splay
    bzoj 2326 矩阵乘法
    bzoj 1702 贪心,前缀和
    bzoj 1700 Problem Solving 解题 dp
  • 原文地址:https://www.cnblogs.com/lasdaybg/p/9718657.html
Copyright © 2011-2022 走看看