• Spring Boot - devtools 热部署


    spring-boot-devtools是Spring Boot提供的一组开发工具,它旨在提高开发体验。这些工具包括应用程序的自动重新启动、自动刷新和远程调试等功能。下面是将spring-boot-devtools整合到Spring Boot应用程序中的步骤:

    0、启用"Build project automatically"(自动构建项目)选项

    在这里插入图片描述

    1、添加必要的依赖

     		
                org.springframework.boot
                spring-boot-devtools
                
                true
                
                runtime
            
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    2、在application.yml添加一些 DevTools 配置

    # Spring Boot DevTools 配置
    spring:
      # DevTools 配置
      devtools:
        # 自动重启配置
        restart:
          # 启用自动重启
          enabled: true
          # 轮询间隔,检测文件变化的时间间隔
          poll-interval: 2s
          # 安静期间,避免重复触发的时间间隔
          quiet-period: 1s
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    3、来个controller简单示范

    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/")
    public class MyController {
    
        // http://localhost:8080/hello
        @GetMapping("/hello")
        public String hello() {
            return "Hello, Spring Boot 111!";
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    4、修改启动配置: 勾选失去焦点时执行更新

    在这里插入图片描述

    5、启动日志里面会有这么一行

     --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
    
    
    • 1
    • 2

    访问接口:
    在这里插入图片描述
    修改一下,再次访问:
    在这里插入图片描述
    如果刚刚的日志清空了,可见控制台第一行:

    Restarting due to 1 class path change (0 additions, 0 deletions, 1 modification)
    
    • 1

    0添加 0删除 1修改

  • 相关阅读:
    Gerrit:ssh key 配置/报错:Permission denied (publickey)
    Java函数式编程:二、高阶函数,闭包,函数组合以及柯里化
    ARM-A架构入门基础(一)预备知识
    工作是做得完的
    每日刷题记录 (二十四)
    C++ 13:面向对象,继承,1-100相加
    自动增加 Android App 的版本号
    5月29日-shell复习
    Linux 文件链接
    Soundness
  • 原文地址:https://blog.csdn.net/qq_43116031/article/details/134471867