SpringBoot-起動アプリケーションおよびコールバックリスナー

メインクラスのメインメソッド

パブリック静的無効メイン(文字列[] args){ 
	SpringApplication.run(SpringBootRunApplication.class、引数)。
}

SpringApplicationを作成されたオブジェクト

パブリック静的ConfigurableApplicationContextラン(<?>クラス[] primarySources、String []型引数){ 
	リターン(新SpringApplication(primarySources))、実行(引数)。
}  

  コンストラクタ

公共SpringApplication(ResourceLoader resourceLoader、クラス... primarySources <?>){ 
	this.sources =新しいLinkedHashSetの(); 
	this.bannerMode = Mode.CONSOLE。
	this.logStartupInfoは真=。
	this.addCommandLineProperties =はtrue。
	this.addConversionService =はtrue。
	this.headless =はtrue。
	this.registerShutdownHookは真=。
	this.additionalProfiles =新しいHashSetの(); 
	this.isCustomEnvironment = falseは、
	this.lazyInitialization = falseは、
	this.resourceLoader = resourceLoader。
	Assert.notNull(primarySources、 "PrimarySourcesがnullであってはなりません")。
	this.primarySources =新しいLinkedHashSetの(は、Arrays.asList(primarySources));
	this.webApplicationType = WebApplicationType.deduceFromClasspath()。
	this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class))。
	this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class))。
	this.mainApplicationClass = this.deduceMainApplicationClass()。
}

  ApplicationContextInitializer&ApplicationListener

    読書META-INF /クラスファイルをspring.factories 

this.setInitializers(this.getSpringFactoriesInstances(ApplicationContextInitializer.class))。
this.setListeners(this.getSpringFactoriesInstances(ApplicationListener.class))。

ファイル名を指定して実行する方法 

RUN ConfigurableApplicationContext公開(文字列...引数){ 
	ストップウォッチストップウォッチストップウォッチ新新=(); 
	stopWatch.start(); 
	// IOCコンテナ
	ConfigurableApplicationContextコンテキスト= NULL; 
	コレクション<SpringBootExceptionReporter> =新新exceptionReportersのArrayList(); 
	this.configureHeadlessProperty() ; 
	//読みMETA-INF / spring.factories SpringApplicationRunListener実装クラスファイルセットの取得
	SpringApplicationRunListenersリスナー= this.getRunListeners(引数); 
	//すべての出発()メソッドのコールバックSpringApplicationRunListenerを聴き始める
	listeners.startingを(); 

	コレクションexceptionReporters ; 
	試み{ 
		applicationArguments applicationArguments =新しい新しいDefaultApplicationArguments(引数)。
		//環境を設定するには、聞くことは準備ができている、コールバックはすべてSpringApplicationRunListener()メソッドenvironmentPrepared 
		/ contextLoaded()メソッドの/コールバックSpringApplicationRunListener
		ConfigurableEnvironment環境= this.prepareEnvironment(リスナー、applicationArguments)。
		this.configureIgnoreBeanInfo(環境)。
		バナーprintedBanner = this.printBanner(環境)。
		//创建IOC容器
		コンテキスト= this.createApplicationContext()。
		exceptionReporters = this.getSpringFactoriesInstances(SpringBootExceptionReporter.class、新しいクラス[] {ConfigurableApplicationContext.class}、コンテキスト)。
		//回调ApplicationContextInitializer的初期化()方法、回调SpringApplicationRunListener的contextPrepared()方法
		this.prepareContext(コンテキスト、環境、リスナー、applicationArguments、printedBanner)。
		//刷新IOC容器、注入组件
		this.refreshContext(コンテキスト)。
		this.afterRefresh(コンテキスト、applicationArguments)。
		stopWatch.stop(); 
		IF(this.logStartupInfo){ 
			(新しい新しいStartupInfoLogger(this.mainApplicationClass))logStarted(this.getApplicationLog()、ストップウォッチ); 
		} 
		//コールバックSpringApplicationRunListener開始()メソッド
		listeners.started(コンテキスト) ; 
		//、IOC ApplicationRunnerから容器を得るすべてのコンポーネントCommandLineRunner、コールバックApplicationRunner、CommandLineRunner run()メソッドの
		this.callRunners(コンテキスト、applicationArguments); 
	}キャッチ(Throwableをvar10){ 
		this.handleRunFailure(文脈、var10、exceptionReporters、リスナー); 
		スロー新しい新しいIllegalStateExceptionを(var10); 
	} 
		listeners.running(コンテキスト); 
		戻り値のコンテキスト。
 
	試み{
		//回调SpringApplicationRunListener的実行()方法
	}キャッチ(Throwableをvar9){ 
		this.handleRunFailure(文脈、var9、exceptionReporters、(SpringApplicationRunListeners)NULL); 
		新しいIllegalStateExceptionを(var9)を投げます。
	} 
}

  

  

おすすめ

転載: www.cnblogs.com/BINGJJFLY/p/12034505.html