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

Springboot自動(dòng)掃描包路徑來龍去脈示例詳解

 更新時(shí)間:2020年12月21日 10:19:05   作者:Aqu415  
這篇文章主要介紹了Springboot自動(dòng)掃描包路徑來龍去脈示例詳解,本文通過示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

我們暫且標(biāo)注下Springboot啟動(dòng)過程中較為重要的邏輯方法,源碼對(duì)應(yīng)的spring-boot-2.2.2.RELEASE版本

public ConfigurableApplicationContext run(String... args) {
		StopWatch stopWatch = new StopWatch();
		stopWatch.start();
		ConfigurableApplicationContext context = null;
		Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();
		configureHeadlessProperty();
		SpringApplicationRunListeners listeners = getRunListeners(args);
		listeners.starting();
		try {
			ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);
			ConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArguments);
			configureIgnoreBeanInfo(environment);
			Banner printedBanner = printBanner(environment);
			//@A
			context = createApplicationContext();
			exceptionReporters = getSpringFactoriesInstances(SpringBootExceptionReporter.class,
					new Class[] { ConfigurableApplicationContext.class }, context);
			//@B
			prepareContext(context, environment, listeners, applicationArguments, printedBanner);
			//@C
			refreshContext(context);
			afterRefresh(context, applicationArguments);
			stopWatch.stop();
			if (this.logStartupInfo) {
				new StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(), stopWatch);
			}
			listeners.started(context);
			callRunners(context, applicationArguments);
		}
		catch (Throwable ex) {
			handleRunFailure(context, ex, exceptionReporters, listeners);
			throw new IllegalStateException(ex);
		}

		try {
			listeners.running(context);
		}
		catch (Throwable ex) {
			handleRunFailure(context, ex, exceptionReporters, null);
			throw new IllegalStateException(ex);
		}
		return context;
	}

第一步:ConfigurationClassPostProcessor注入

org.springframework.context.annotation.ConfigurationClassPostProcessor是一個(gè)BeanDefinitionRegistryPostProcessor(父類是BeanFactoryPostProcessor),會(huì)在容器初始化好并裝載完第一階段的bean定義后調(diào)用,我理解的其主要作用是執(zhí)行一些框架內(nèi)部方法也讓用戶自定義再次注入自定義的bean定義;

它的注冊(cè)是在SpringApplication.run方法調(diào)用后,具體調(diào)用鏈?zhǔn)?/p>

org.springframework.boot.SpringApplication#run(java.lang.Class<?>, java.lang.String...)
->org.springframework.boot.SpringApplication#run(java.lang.String...)
->org.springframework.boot.SpringApplication#createApplicationContext 
//對(duì)應(yīng)上面@A標(biāo)注的地方
//后續(xù)會(huì)初始化一個(gè)org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext對(duì)象,在構(gòu)造方法里會(huì)執(zhí)行一系列的邏輯
->org.springframework.context.annotation.AnnotatedBeanDefinitionReader#AnnotatedBeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionRegistry)
->org.springframework.context.annotation.AnnotatedBeanDefinitionReader#AnnotatedBeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionRegistry, org.springframework.core.env.Environment)
->org.springframework.context.annotation.AnnotationConfigUtils#registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry)
->org.springframework.context.annotation.AnnotationConfigUtils#registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry, java.lang.Object)

//這個(gè)方法會(huì)注入5個(gè)bean定義:
1. ConfigurationClassPostProcessor.class
2. AutowiredAnnotationBeanPostProcessor.class
3. CommonAnnotationBeanPostProcessor.class
4. EventListenerMethodProcessor.class
5. DefaultEventListenerFactory.class

第二步:啟動(dòng)類bean定義注入

被我們標(biāo)記了@SpringBootApplication的類在運(yùn)行過程中會(huì)被包裝成一個(gè)bean定義,放入容器中;具體方法調(diào)用鏈

org.springframework.boot.SpringApplication#run(java.lang.String...)
org.springframework.boot.SpringApplication#prepareContext //對(duì)應(yīng)上面代碼標(biāo)注 @B 的地方
org.springframework.boot.SpringApplication#load
org.springframework.boot.BeanDefinitionLoader#load(java.lang.Object)
org.springframework.boot.BeanDefinitionLoader#load(java.lang.Class<?>)
org.springframework.context.annotation.AnnotatedBeanDefinitionReader#register
org.springframework.context.annotation.AnnotatedBeanDefinitionReader#registerBean(java.lang.Class<?>)
org.springframework.context.annotation.AnnotatedBeanDefinitionReader#doRegisterBean

//里面一段代碼 如下:
AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(beanClass);
//從這個(gè)方法里可以看出,啟動(dòng)類被包裝成了 AnnotatedGenericBeanDefinition(實(shí)現(xiàn)了AnnotatedBeanDefinition接口,這很重要)

第三步:解析包掃描信息并完成剩余bean注冊(cè)

剛剛在第一步里,容器中注入了ConfigurationClassPostProcessor后置處理器,后置處理器會(huì)在核心方法refresh中執(zhí)行,也就是上面標(biāo)注@C的代碼里;

我們直接來到核心邏輯處,調(diào)用鏈:

ConfigurationClassPostProcessor方法被調(diào)用

由于第二步容器中將啟動(dòng)類包裝成AnnotatedGenericBeanDefinition并注入了容器,在方法
org.springframework.context.annotation.ConfigurationClassParser#parse(java.util.Set<org.springframework.beans.factory.config.BeanDefinitionHolder>)會(huì)被處理執(zhí)行后續(xù)的包掃描

到此這篇關(guān)于Springboot自動(dòng)掃描包路徑來龍去脈示例詳解的文章就介紹到這了,更多相關(guān)Springboot自動(dòng)掃描包路徑內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • SpringBoot中的server.context-path的實(shí)現(xiàn)

    SpringBoot中的server.context-path的實(shí)現(xiàn)

    本文主要介紹了SpringBoot中的server.context-path的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-08-08
  • java實(shí)現(xiàn)String類型和Date類型相互轉(zhuǎn)換

    java實(shí)現(xiàn)String類型和Date類型相互轉(zhuǎn)換

    很多人表示,java將string類型轉(zhuǎn)為date類型不知道應(yīng)該怎樣做,本文就來介紹一下java實(shí)現(xiàn)String類型和Date類型相互轉(zhuǎn)換,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • SpringCloud?Gateway?DispatcherHandler調(diào)用方法詳細(xì)介紹

    SpringCloud?Gateway?DispatcherHandler調(diào)用方法詳細(xì)介紹

    我們第一個(gè)關(guān)注的類就是DispatcherHandler,這個(gè)類提供的handle()方法,封裝了我們之后所有的handlerMappings,這個(gè)DispatcherHandler有點(diǎn)想SpringMVC的DispatchServlet,里面也是封裝了請(qǐng)求和對(duì)應(yīng)的處理方法的關(guān)系
    2022-10-10
  • java調(diào)用shell腳本及注意事項(xiàng)說明

    java調(diào)用shell腳本及注意事項(xiàng)說明

    這篇文章主要介紹了java調(diào)用shell腳本及注意事項(xiàng)說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-06-06
  • Java Agent入門學(xué)習(xí)之動(dòng)態(tài)修改代碼

    Java Agent入門學(xué)習(xí)之動(dòng)態(tài)修改代碼

    這篇文章主要給大家分享了Java Agent入門學(xué)習(xí)之動(dòng)態(tài)修改代碼的相關(guān)資料,文中介紹的非常詳細(xì),對(duì)大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起看看吧。
    2017-07-07
  • Spring Mybatis 分頁插件使用教程

    Spring Mybatis 分頁插件使用教程

    這篇文章主要介紹了Spring Mybatis分頁插件使用教程,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2018-02-02
  • maven中no main manifest attribute的問題解決

    maven中no main manifest attribute的問題解決

    本文主要介紹了maven中no main manifest attribute的問題解決,這個(gè)錯(cuò)誤通常意味著Spring Boot應(yīng)用在啟動(dòng)時(shí)遇到了問題,下面就來具體介紹一下,感興趣的可以了解一下
    2024-08-08
  • java maven項(xiàng)目如何讀取配置文件信息

    java maven項(xiàng)目如何讀取配置文件信息

    這篇文章主要介紹了java maven項(xiàng)目如何讀取配置文件信息,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-11-11
  • Java中Exception和Error的區(qū)別詳解

    Java中Exception和Error的區(qū)別詳解

    這篇文章主要介紹了Java中Exception和Error的區(qū)別詳解,通過類的關(guān)系分析兩者的區(qū)別與應(yīng)用場景,包含代碼實(shí)例,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-07-07
  • java普通項(xiàng)目讀取不到resources目錄下資源文件的解決辦法

    java普通項(xiàng)目讀取不到resources目錄下資源文件的解決辦法

    這篇文章主要給大家介紹了關(guān)于java普通項(xiàng)目讀取不到resources目錄下資源文件的解決辦法,Web項(xiàng)目中應(yīng)該經(jīng)常有這樣的需求,在maven項(xiàng)目的resources目錄下放一些文件,比如一些配置文件,資源文件等,需要的朋友可以參考下
    2023-09-09

最新評(píng)論

贞丰县| 监利县| 蚌埠市| 沅江市| 湘阴县| 梁山县| 金阳县| 蒙阴县| 新宁县| 青州市| 阜南县| 昔阳县| 商洛市| 恩施市| 忻州市| 赤城县| 神木县| 桐柏县| 临漳县| 治县。| 天气| 文山县| 德安县| 松江区| 德令哈市| 台中县| 湘乡市| 佛坪县| 德惠市| 上林县| 共和县| 木兰县| 洞口县| 察雅县| 元江| 菏泽市| 贵阳市| 托克逊县| 津市市| 北碚区| 体育|