国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

SpringBoot 創建容器的實現

瀏覽:31日期:2023-04-17 18:01:41

spring 容器的創建對應 SpringApplication 中 run 中調用的 createApplicationContext 方法。這里創建了一個 web 容器,接下就進去 prepareContext 容器準備階段:

private void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners, ApplicationArguments applicationArguments, Banner printedBanner) { //為容器設置環境 context.setEnvironment(environment); //這里的空實現留給開發者擴展,設置數據轉換的ConversionService postProcessApplicationContext(context); //執行容器中的 Initializers 的 initialize 方法 applyInitializers(context); listeners.contextPrepared(context); if (this.logStartupInfo) { logStartupInfo(context.getParent() == null); logStartupProfileInfo(context); } // Add boot specific singleton beans ConfigurableListableBeanFactory beanFactory = context.getBeanFactory(); beanFactory.registerSingleton('springApplicationArguments', applicationArguments); if (printedBanner != null) { beanFactory.registerSingleton('springBootBanner', printedBanner); } if (beanFactory instanceof DefaultListableBeanFactory) { ((DefaultListableBeanFactory) beanFactory) .setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding); } if (this.lazyInitialization) { context.addBeanFactoryPostProcessor(new LazyInitializationBeanFactoryPostProcessor()); } // Load the sources Set<Object> sources = getAllSources(); Assert.notEmpty(sources, 'Sources must not be empty'); load(context, sources.toArray(new Object[0])); listeners.contextLoaded(context); }

看一下這里的 load 方法,這里主要把我們的啟動類作為 Bean 注冊到了 Spring 的容器中。

protected void load(ApplicationContext context, Object[] sources) { if (logger.isDebugEnabled()) { logger.debug('Loading source ' + StringUtils.arrayToCommaDelimitedString(sources)); } BeanDefinitionLoader loader = createBeanDefinitionLoader(getBeanDefinitionRegistry(context), sources); if (this.beanNameGenerator != null) { loader.setBeanNameGenerator(this.beanNameGenerator); } if (this.resourceLoader != null) { loader.setResourceLoader(this.resourceLoader); } if (this.environment != null) { loader.setEnvironment(this.environment); } loader.load(); }

/** * Load the sources into the reader. * @return the number of loaded beans */ int load() { int count = 0; for (Object source : this.sources) { count += load(source); } return count; } private int load(Object source) { Assert.notNull(source, 'Source must not be null'); if (source instanceof Class<?>) { return load((Class<?>) source); } if (source instanceof Resource) { return load((Resource) source); } if (source instanceof Package) { return load((Package) source); } if (source instanceof CharSequence) { return load((CharSequence) source); } throw new IllegalArgumentException('Invalid source type ' + source.getClass()); } private int load(Class<?> source) { if (isGroovyPresent() && GroovyBeanDefinitionSource.class.isAssignableFrom(source)) { // Any GroovyLoaders added in beans{} DSL can contribute beans here GroovyBeanDefinitionSource loader = BeanUtils.instantiateClass(source, GroovyBeanDefinitionSource.class); load(loader); } if (isEligible(source)) { this.annotatedReader.register(source); return 1; } return 0; }

再來看下 contextLoaded 方法,這里將上下文設置到監聽器中,同時也把監聽器添加到上下文中。最后發布了一個 ApplicationPreparedEvent 事件。

public void contextLoaded(ConfigurableApplicationContext context) { for (ApplicationListener<?> listener : this.application.getListeners()) { if (listener instanceof ApplicationContextAware) {((ApplicationContextAware) listener).setApplicationContext(context); } context.addApplicationListener(listener); } this.initialMulticaster.multicastEvent(new ApplicationPreparedEvent(this.application, this.args, context)); }

到此這篇關于SpringBoot 創建容器的實現的文章就介紹到這了,更多相關SpringBoot 創建容器內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 精品国产日韩亚洲一区在线 | 日本免费人做人一区在线观看 | 国产精品拍自在线观看 | 亚欧色视频在线观看免费 | 美国一级毛片片aa成人 | 99精品国产一区二区三区 | 国产成人在线免费视频 | 毛片在线视频观看 | 欧美一级高清免费播放 | 亚洲男人的天堂久久香蕉网 | 日本xxxb孕交 | 亚洲特一级毛片 | 99久久精品免费观看国产 | 在线观看中文字幕国产 | 日本久久一区二区 | 精品久久影院 | 国产精品亚洲专一区二区三区 | 日本美女作爱 | 毛片网站大全 | 亚洲欧美日韩国产综合 | 亚洲系列中文字幕一区二区 | 一级特级欧美aaaaa毛片 | 国产成人久久精品二区三区牛 | 国产一级特黄全黄毛片 | 精品91一区二区三区 | 成年人免费软件 | 精品视频在线免费看 | 精品成人在线 | 性欧美f| 免费v片视频在线观看视频 免费v片在线观看 | 久草在线最新 | 中文国产成人精品久久一 | 久久亚洲精品永久网站 | 九九99靖品 | 欧美一区二区精品系列在线观看 | 国产成人欧美视频在线 | 久草久草 | 亚洲天堂网在线视频 | 日韩精品a| 国产成人亚洲毛片 | 国产精品一区二区手机在线观看 |