欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

springBoot啟動時怎么選擇可執(zhí)行的任務

本篇文章給大家分享的是有關springBoot啟動時怎么選擇可執(zhí)行的任務,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

創(chuàng)新互聯(lián)公司憑借專業(yè)的設計團隊扎實的技術支持、優(yōu)質(zhì)高效的服務意識和豐厚的資源優(yōu)勢,提供專業(yè)的網(wǎng)站策劃、網(wǎng)站設計、網(wǎng)站建設、網(wǎng)站優(yōu)化、軟件開發(fā)、網(wǎng)站改版等服務,在成都十載的網(wǎng)站建設設計經(jīng)驗,為成都上千余家中小型企業(yè)策劃設計了網(wǎng)站。

CommandLineRunner

看源碼說明為:

Spring Batch jobs. Runs all  jobs in the surrounding context by default. Can also be used to launch a specific job
  by providing a jobName。

即,在spring容器啟動的時候就開始批處理一些任務。是隨spring啟動而加載運行的。

使用方式:自定義一個model 實現(xiàn)該及接口并重寫run 方法

package org.springboot.sample.runner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class MyStartupRunner implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
System.out.println(">>>>>>>>>>>>>>>服務啟動執(zhí)行,執(zhí)行加載數(shù)據(jù)等操作<<<<<<<<<<<<<");
}

}

===========如果有多個類實現(xiàn)CommandLineRunner接口,如何保證順序??? @Order注解 來實現(xiàn)

package org.springboot.sample.runner;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


@Component
@Order(value=2)
public class MyStartupRunner1 implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
System.out.println(">>>>>>>>>>>>>>>服務啟動執(zhí)行 2222 <<<<<<<<<<<<<");
}

}
```
```
package org.springboot.sample.runner;

import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Order(value=1)
public class MyStartupRunner2 implements CommandLineRunner {

@Override
public void run(String... args) throws Exception {
System.out.println(">>>>>>>>>>>>>>>服務啟動執(zhí)行 111111 <<<<<<<<<<<<<");
}

}
```
> 控制臺顯示
```
>>>>>>>>>>>>>>>服務啟動執(zhí)行 11111111 <<<<<<<<<<<<<
>>>>>>>>>>>>>>>服務啟動執(zhí)行 22222222## 標題 ## <<<<<<<<<<<<<
```
> 根據(jù)控制臺結果可判斷,@Order 注解的執(zhí)行優(yōu)先級是按value值從小到大順序。

改接口常用語 boot 啟動初始化時 加載一些配置常量。比如一些三方的訪問接口配置常量。

例如:

package com.big.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;


import lombok.Getter;
@Component
@Getter
public class RiskConstants  implements CommandLineRunner{
	@Autowired
	private Environment env;
	/**常數(shù)項配置*/
	public static final String TD_URL_DOMAIN = "";
	
	
	

	@Override
	public void run(String... args) throws Exception {
		RiskConstants.TD_URL_DOMAIN = env.getProperty("t.url.domain");


		System.out.println("===============配置文件  config加載完成-------------------------");
	}
}

以上就是springBoot啟動時怎么選擇可執(zhí)行的任務,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學到更多知識。更多詳情敬請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

網(wǎng)頁名稱:springBoot啟動時怎么選擇可執(zhí)行的任務
文章分享:http://www.chinadenli.net/article32/gpdjsc.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供標簽優(yōu)化網(wǎng)站營銷關鍵詞優(yōu)化App設計網(wǎng)站內(nèi)鏈網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設網(wǎng)站維護公司