最近2018中文字幕在日韩欧美国产成人片_国产日韩精品一区二区在线_在线观看成年美女黄网色视频_国产精品一区三区五区_国产精彩刺激乱对白_看黄色黄大色黄片免费_人人超碰自拍cao_国产高清av在线_亚洲精品电影av_日韩美女尤物视频网站

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
springBoot啟動時怎么選擇可執(zhí)行的任務(wù)

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

創(chuàng)新互聯(lián)公司憑借專業(yè)的設(shè)計團隊扎實的技術(shù)支持、優(yōu)質(zhì)高效的服務(wù)意識和豐厚的資源優(yōu)勢,提供專業(yè)的網(wǎng)站策劃、網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、網(wǎng)站優(yōu)化、軟件開發(fā)、網(wǎng)站改版等服務(wù),在成都十載的網(wǎng)站建設(shè)設(shè)計經(jīng)驗,為成都上千余家中小型企業(yè)策劃設(shè)計了網(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容器啟動的時候就開始批處理一些任務(wù)。是隨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(">>>>>>>>>>>>>>>服務(wù)啟動執(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(">>>>>>>>>>>>>>>服務(wù)啟動執(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(">>>>>>>>>>>>>>>服務(wù)啟動執(zhí)行 111111 <<<<<<<<<<<<<");
}

}
```
> 控制臺顯示
```
>>>>>>>>>>>>>>>服務(wù)啟動執(zhí)行 11111111 <<<<<<<<<<<<<
>>>>>>>>>>>>>>>服務(wù)啟動執(zhí)行 22222222## 標題 ## <<<<<<<<<<<<<
```
> 根據(jù)控制臺結(jié)果可判斷,@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í)行的任務(wù),小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


本文名稱:springBoot啟動時怎么選擇可執(zhí)行的任務(wù)
文章來源:http://fisionsoft.com.cn/article/gpdjsc.html