SpringBoot热部署详解

简介: SpringBoot热部署详解

在这里插入图片描述

🍁博客主页:👉 不会压弯的小飞侠
✨欢迎关注:👉点赞👍收藏⭐留言✒
✨系列专栏:👉 SpringBoot专栏(每日更新)
✨如果觉得博主的文章还不错的话,请三连支持一下博主。
🔥欢迎大佬指正,一起 学习!一起加油!
在这里插入图片描述

@TOC


🍁前言

热部署,就是不需要停掉服务,可以线上改,改完立马生效。

🍁为什么要使用热部署

因为不启用热部署时每次更改java数据都要重启服务器影响开发效率。

🔥关于热部署:

  • 重启(Restart)∶自定义开发代码,包含类、页面、配置文件等,加载位置restart类加载器
  • 重载(ReLoad) : jar包,加载位置base类加载器

🍁手动启动热部署

🔥导入坐标 - 启动开发者工具

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>

🔥修改数据

方便测试是否启用了热部署:
详细代码:点击直接查看

 @GetMapping("{id}")
    public R getById(@PathVariable Integer id){
        System.out.println("host deploy...");
        System.out.println("host deploy...");
        System.out.println("host deploy...");
        return new R(true, bookService.getById(id));
    }

🔥build project

也可以使用快捷键: ctrl + shift9
在这里插入图片描述

🔥测试

在这里插入图片描述

🍁自动启动热部署

自动启动热部署步骤:

  1. file
  2. setting
  3. 搜索Compiler,在右侧勾上 “ Build project automatically在这里插入图片描述
  4. 快键键Ctrl+atl+shift+/
  5. 点击Registry 在这里插入图片描述
  6. 勾选第一行这个如下图 在这里插入图片描述

🍁热部署范围配置

如果想要某些文件或者文件夹不参与热部署的配置需要在application.xml中配置以下信息:

# 设置不参与热部署的文件或文件夹
devtools:
  restart:
    exclude: static/**,public/**,config/application.yml

🍁禁用热部署

🔥方式一

在application.yml中配置:

# 设置不参与热部署的文件或文件夹
devtools:
  restart:
    exclude: static/**,public/**,config/application.yml
    enabled: false

这种形式关闭热部署,优先级别太低,可能关闭之后,别人又从别的配置文件或者其他地方给打开了(在优先级别高的地方),从而导致热部署在此启动.

🔥方式二

🔥在优先级别高的地方禁用热部署。

  • 属性加载优先顺序:由低到高

    • 1 Default properties (specified by setting springApplication.setDefaultproperties )
    • 2 GPropertySsource annotations on your @Cconfiguration classes. Please note that such property sources are not added to theEnvironment until the application context is being refreshed.This is too late to configure certain properties such as logging. and spring.main. which are read before refresh begins.
    • 3 Config data (such as application.properties files)
    • 4 A RandomValuePropertySource that has properties only in random.* .
    • 5 OS environment variables.
    • 6 Java System properties ( system.getProperties() ).
    • 7 JNDl attributes from java:comp/env .
    • 8 ServletContext init parameters.
    • 9 Servletconfig init parameters.
    • 10 Properties from spRING_APpLICATION_soN (inline JSON embedded in an environment variable or system property).
    • 11 Command line arguments.
    • 12 properties attribute on your tests.Available on gSpringRootTest and the test annotations for testing a particular slice ofyour application.
    • 13 @TestPropertySource annotations on your tests.
    • 14 Devtools global settings properties in the SHN'E .config/spring-boot directory when devtools ,s.ati

🔥application.yml配置文件在优先级为3的地方,可以在优先级为6的地方禁用热部署功能:

package com.jkj;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringbootHotDeployApplication {
    public static void main(String[] args) {
        System.setProperty("spring.devtools.restart.enabled","false");
        SpringApplication.run(SpringbootHotDeployApplication.class);
    }

}

在这里插入图片描述

相关文章
|
Web App开发 前端开发 JavaScript
SpringBoot开发模式自动重启热部署spring-boot-devtools
SpringBoot开发模式自动重启热部署spring-boot-devtools
156 0
SpringBoot开发模式自动重启热部署spring-boot-devtools
|
Java
【Java】【SpringBoot】CP03:热部署
【Java】【SpringBoot】CP03:热部署
131 0
【Java】【SpringBoot】CP03:热部署
|
监控 IDE Java
《SpringBoot篇》06.超详细热部署教学
《SpringBoot篇》06.超详细热部署教学
180 0
《SpringBoot篇》06.超详细热部署教学
|
搜索推荐 Java Maven
idea springboot 热部署,让项目不再重启
idea springboot 热部署,让项目不再重启
443 0
idea springboot 热部署,让项目不再重启
|
Java
第八篇:SpringBoot热部署 如何打开热部署 如何控制热部署的范围 如何关闭热部署
第八篇:SpringBoot热部署 如何打开热部署 如何控制热部署的范围 如何关闭热部署
206 0
第八篇:SpringBoot热部署 如何打开热部署 如何控制热部署的范围 如何关闭热部署
|
监控 IDE Java
SpringBoot实现热部署笔记
SpringBoot实现热部署笔记
SpringBoot实现热部署笔记
|
XML 设计模式 前端开发
Java笔记:SpringBoot热部署与热加载
Java笔记:SpringBoot热部署与热加载
686 0
|
Web App开发 监控 前端开发
SpringBoot2.x系列教程05--SpringBoot花样配置之实现热部署配置及原理
前言 上一章节中,壹哥 带各位学会了配置自定义的Web端口与项目根目录,今天我们再来看看其他的一些小花样。 在开发阶段,我们编写完代码后,就得需要点击启动按钮,重启项目后才能看到更新后的内容,每次都这么操作,就会就得有点麻烦,那能不能让项目随着代码的更新而自动重启呢? 既然有了这样的需求,SpringBoot就很暖心的给我们提供了这样的功能。今天我们就来看看SpringBoot中的另一个小花样配置---实现SpringBoot项目的热加载。 注意 网上也有不少教程把该功能称为热部署,我觉得叫做热加载更准确点! 一. SpringBoot热加载简介 在SpringBoot中实现热加载相对来说
282 0
Java:Springboot 实现热部署的两种方式
Java:Springboot 实现热部署的两种方式
Java:Springboot 实现热部署的两种方式
|
Java 开发者
三步实现Idea的springboot配置热部署(修改代码自动启动springboot程序)
三步实现Idea的springboot配置热部署(修改代码自动启动springboot程序)