最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot自動重啟的兩種方法

 更新時間:2023年12月08日 09:17:54   作者:Fisher3652  
我們在項(xiàng)目開發(fā)階段,可能經(jīng)常會修改代碼,修改完后就要重啟Spring Boot,本文主要介紹了SpringBoot自動重啟的兩種方法,具有一定的參考價值,感興趣的可以了解一下

方法一:使用SpringCloud RestartEndpoint

  • 使用的jar
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    implementation 'org.springframework.cloud:spring-cloud-starter-config:3.0.7'
  • 在application.properties添加配置
management.endpoint.restart.enabled=true
spring.cloud.config.enabled=false
  • 重啟方法的Controller
import javax.annotation.Resource;

import org.springframework.cloud.context.restart.RestartEndpoint;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/restart")
public class RestartController {

    @Resource
    private RestartEndpoint restartEndpoint;

    @GetMapping("/restartApplication")
    public void restartApplication() {
        restartEndpoint.restart();
    }

}

方法二:重新創(chuàng)建ApplicationContext上下文

  • 啟動類
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class Application {

    public static ConfigurableApplicationContext context;

    public static void main(String[] args) {
        context = SpringApplication.run(Application.class);
    }

}

  • 重啟方法的Controller
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/restart")
public class RestartController {

    private static void restart() {
        ApplicationArguments args = Application.context.getBean(ApplicationArguments.class);
        Thread thread = new Thread(() -> {
            log.info("springboot restart...");
            Application.context.close();
            Application.context = SpringApplication.run(Application.class, args.getSourceArgs());
        });
        // 設(shè)置為用戶線程,不是守護(hù)線程
        thread.setDaemon(false);
        thread.start();
    }
}

到此這篇關(guān)于SpringBoot自動重啟的兩種方法的文章就介紹到這了,更多相關(guān)SpringBoot自動重啟內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家! 

相關(guān)文章

  • Springboot集成JSR303參數(shù)校驗(yàn)的方法實(shí)現(xiàn)

    Springboot集成JSR303參數(shù)校驗(yàn)的方法實(shí)現(xiàn)

    這篇文章主要介紹了Springboot集成JSR303參數(shù)校驗(yàn)的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • 使用EasyPoi實(shí)現(xiàn)百萬級數(shù)據(jù)導(dǎo)出的性能優(yōu)化方案

    使用EasyPoi實(shí)現(xiàn)百萬級數(shù)據(jù)導(dǎo)出的性能優(yōu)化方案

    Easypoi 功能如同名字easy,主打的功能就是容易,讓一個沒見接觸過poi的人員 就可以方便的寫出Excel導(dǎo)出,Excel模板導(dǎo)出,Excel導(dǎo)入,本文給大家介紹了使用EasyPoi實(shí)現(xiàn)百萬級數(shù)據(jù)導(dǎo)出的性能優(yōu)化方案,需要的朋友可以參考下
    2025-08-08
  • SpringBoot2零基礎(chǔ)到精通之profile功能與自定義starter

    SpringBoot2零基礎(chǔ)到精通之profile功能與自定義starter

    SpringBoot是一種整合Spring技術(shù)棧的方式(或者說是框架),同時也是簡化Spring的一種快速開發(fā)的腳手架,本篇讓我們一起學(xué)習(xí)profile功能與自定義starter
    2022-03-03
  • 詳解Spring Cloud Zuul重試機(jī)制探秘

    詳解Spring Cloud Zuul重試機(jī)制探秘

    本篇文章主要介紹了詳解Spring Cloud Zuul重試機(jī)制探秘,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-11-11
  • SpringBoot Maven 項(xiàng)目 pom 中的 plugin 插件用法小結(jié)

    SpringBoot Maven 項(xiàng)目 pom 中的 plugin&n

    本文詳細(xì)介紹了Spring Boot Maven項(xiàng)目打包成jar文件時使用的spring-boot-maven-plugin插件,深入探討了插件的配置元素,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧
    2025-01-01
  • Spring?Boot?優(yōu)雅停機(jī)原理詳解

    Spring?Boot?優(yōu)雅停機(jī)原理詳解

    這篇文章主要為大家介紹了Spring?Boot?優(yōu)雅停機(jī)原理詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • MyBatis-Plus邏輯刪除實(shí)現(xiàn)過程

    MyBatis-Plus邏輯刪除實(shí)現(xiàn)過程

    本文介紹了MyBatis-Plus如何實(shí)現(xiàn)邏輯刪除功能,包括自動填充字段、配置與實(shí)現(xiàn)步驟、常見應(yīng)用場景,并展示了如何使用remove方法進(jìn)行邏輯刪除,邏輯刪除通過修改字段值來標(biāo)記數(shù)據(jù)為刪除狀態(tài),保留數(shù)據(jù)歷史記錄,避免數(shù)據(jù)丟失
    2025-12-12
  • Java 線程相關(guān)總結(jié)

    Java 線程相關(guān)總結(jié)

    這篇文章主要介紹了Java 線程的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)使用Java,感興趣的朋友可以了解下
    2021-02-02
  • Java設(shè)計圖形與多媒體處理

    Java設(shè)計圖形與多媒體處理

    本文主要介紹了Java的圖形設(shè)計以及多媒體處理,源碼也做了詳細(xì)的注釋,對于初學(xué)者應(yīng)該不難。詳細(xì)請看下文
    2015-09-09
  • JAVA中的基本數(shù)據(jù)類型

    JAVA中的基本數(shù)據(jù)類型

    本文主要介紹了JAVA中的基本數(shù)據(jù)類型。具有很好的參考價值,下面跟著小編一起來看下吧
    2017-02-02

最新評論

晋城| 外汇| 南平市| 罗田县| 抚顺市| 泰和县| 贵德县| 寿阳县| 江油市| 获嘉县| 竹山县| 安图县| 财经| 二连浩特市| 康定县| 眉山市| 昭苏县| 巴东县| 南投市| 雅安市| 密云县| 东兰县| 阿勒泰市| 青海省| 高唐县| 常熟市| 花莲县| 温州市| 亳州市| 闸北区| 河间市| 吕梁市| 天门市| 中超| 益阳市| 南康市| 慈溪市| 邹城市| 兴化市| 巢湖市| 土默特右旗|