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

SpringBoot自動重啟的兩種方法

 更新時間:2023年12月08日 09:17:54   作者:Fisher3652  
我們在項目開發(fā)階段,可能經常會修改代碼,修改完后就要重啟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());
        });
        // 設置為用戶線程,不是守護線程
        thread.setDaemon(false);
        thread.start();
    }
}

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

相關文章

  • Springboot集成JSR303參數校驗的方法實現

    Springboot集成JSR303參數校驗的方法實現

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

    使用EasyPoi實現百萬級數據導出的性能優(yōu)化方案

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

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

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

    詳解Spring Cloud Zuul重試機制探秘

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

    SpringBoot Maven 項目 pom 中的 plugin&n

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

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

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

    MyBatis-Plus邏輯刪除實現過程

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

    Java 線程相關總結

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

    Java設計圖形與多媒體處理

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

    JAVA中的基本數據類型

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

最新評論

奉节县| 内江市| 磴口县| 房产| 福清市| 四会市| 治多县| 武宣县| 历史| 台北县| 靖州| 平定县| 福建省| 马鞍山市| 五指山市| 项城市| 滨州市| 安顺市| 嵩明县| 柳州市| 广元市| 获嘉县| 留坝县| 永顺县| 休宁县| 清苑县| 砚山县| 岳阳市| 吴桥县| 黄大仙区| 贡山| 阜康市| 济源市| 曲阳县| 汝南县| 温泉县| 金门县| 淳化县| 东阳市| 定结县| 吕梁市|