SpringBoot源码解析
2024-03-12 11:38:15 0 举报
Spring Boot源码解析,这是一段深入探讨Spring Boot框架内部结构和工作原理的内容。Spring Boot作为Java开发者广泛使用的微服务框架,其源码解析对于理解Spring Boot的底层实现和优化应用具有重要价值。通过阅读此源码解析,您将了解Spring Boot的核心组件、启动过程、自动配置机制以及各种扩展点等,从而更好地使用Spring Boot进行应用程序开发。
作者其他创作
大纲/内容
tomcat.setBaseDir(baseDir.getAbsolutePath())
DefaultPropertiesPropertySource.moveToEnd(environment)
doWithListeners(\"spring.boot.application.context-loaded\
ExistingWebApplicationScopes existingScopes = new ExistingWebApplicationScopes(getBeanFactory())
lifecycleProcessorLifecycleProcessor.classDefaultLifecycleProcessor()
beanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this))
factory = getWebServerFactory()
bootstrapContext.close(context)
System.setProperty(SYSTEM_PROPERTY_JAVA_AWT_HEADLESS
initMessageSource()
this.log = log;this.listeners = new ArrayList<>(listeners);this.applicationStartup = applicationStartup
abstract class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext
getApplicationEventMulticaster().addApplicationListener(listener)
getApplicationEventMulticaster().addApplicationListenerBean(listenerBeanName)
postProcessApplicationContext(context)
class SpringApplicationRunListeners
this.bootstrappersinitializer.intitialize
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory()
contextRefresh = this.applicationStartup.start(\"spring.context.refresh\")
step = this.applicationStartup.start(stepName)
createWebServer()
clearResourceCaches()
invokeBeanFactoryPostProcessors(beanFactory)
prepareRefresh()
listeners.started(context)
stopWatch.stop()
initPropertySources()
this.listeners.forEach(listenerAction)
stepAction.accept(step)
context = createApplicationContext()
WebApplicationContextUtils.registerWebApplicationScopes(getBeanFactory())
getTomcatWebServer(tomcat)
configureEngine(tomcat.getEngine())
class ServletWebServerApplicationContext extends GenericWebApplicationContext implements ConfigurableWebServerApplicationContext
initLifecycleProcessor()
CachedIntrospectionResults.clearClassLoader(getClassLoader())
environment = getOrCreateEnvironment()
createWebServer.end()
beanPostProcess = this.applicationStartup.start(\"spring.context.beans.post-process\")
registerBeanPostProcessors(beanFactory)
SpringBoot源码解析
beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver(beanFactory.getBeanClassLoader()))
resetCommonCaches()
stopWatch.start()
new SpringApplication(primarySources)
baseDir = (this.baseDirectory != null) ? this.baseDirectory : createTempDir(\"tomcat\")
super.postProcessBeanFactory(beanFactory)
beanFactory.setConversionService
prepareBeanFactory(beanFactory)
beanPostProcess.end()
finishRefresh()
refresh((ApplicationContext) context)
contextRefresh.end()
this.bootstrappers = new ArrayList<>(getSpringFactoriesInstances(Bootstrapper.class));setInitializers((Collection) getSpringFactoriesInstances(ApplicationContextInitializer.class));setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));this.mainApplicationClass = deduceMainApplicationClass()
ResolvableType.clearCache()
doWithListeners(\"spring.boot.application.starting\
existingScopes.restore()
this.webApplicationType = WebApplicationType.deduceFromClasspath()
tomcat = new Tomcat()
super.onRefresh()
connector = new Connector(this.protocol)
context.registerShutdownHook()
super.refresh()
getApplicationEventMulticaster().multicastEvent(earlyEvent)
SpringApplicationRunListeners listeners = getRunListeners(args)
publishEvent(new ContextRefreshedEvent(this))
Banner printedBanner = printBanner(environment)
listeners.contextPrepared(context)
run(args)
doWithListeners(\"spring.boot.application.started\
ConfigurationPropertySources.attach(environment)
class AnnotationConfigServletWebServerApplicationContext extends ServletWebServerApplicationContext implements AnnotationConfigRegistry
registerWebApplicationScopes()
this.resourceLoader = resourceLoader;this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources))
listeners.running(context)
DefaultBootstrapContext bootstrapContext = createBootstrapContext()
this.applicationContextFactory.create(this.webApplicationType)
doWithListeners(\"spring.boot.application.context-prepared\
getLifecycleProcessor().onRefresh()
switch (webApplicationType) {case SERVLET: return new AnnotationConfigServletWebServerApplicationContext();case REACTIVE: return new AnnotationConfigReactiveWebServerApplicationContext();default: return new AnnotationConfigApplicationContext();
context.setEnvironment(environment)
beanFactory.preInstantiateSingletons()
beanFactory.addEmbeddedValueResolver
customizeConnector(connector)
themeSourceHierarchicalThemeSource()DelegatingThemeSource()ResourceBundleThemeSource()
onRefresh()
Set<Object> sources = getAllSources()
configureAdditionalProfiles(environment)
refresh((ConfigurableApplicationContext) applicationContext)
listeners.contextLoaded(context)
beanFactory.addBeanPostProcessor(new ApplicationListenerDetector(this))
refreshContext(context)
AnnotationUtils.clearCache()
super.prepareRefresh()
applicationEventMulticasterApplicationEventMulticaster.classSimpleApplicationEventMulticaster(beanFactory)
beanFactory.setTempClassLoader(null)
connector.setThrowOnFailure(true)
doWithListeners(\"spring.boot.application.environment-prepared\
configureIgnoreBeanInfo(environment)
messageSourceHierarchicalMessageSource()DelegatingMessageSource()
class SpringApplication
tomcat.setConnector(connector)
initApplicationEventMulticaster()
System.setProperty(\"spring.beaninfo.ignore\
tomcat.getHost().setAutoDeploy(false)
beanFactory.ignoreDependencyInterface(ServletContextAware.class)
createWebServer.tag(\"factory\
applyInitializers(context)
postProcessBeanFactory(beanFactory)
registerListeners()
beanFactory.setBeanClassLoader(getClassLoader())
this.themeSource = UiApplicationContextUtils.initThemeSource(this)
doWithListeners(\"spring.boot.application.running\
getBeanFactory()
applicationContext.refresh()
finishBeanFactoryInitialization(beanFactory)
refreshBeanFactory()
beanFactory.freezeConfiguration()
tomcat.getService().addConnector(connector)
configureHeadlessProperty()
ReflectionUtils.clearCache()
this.webServer = factory.getWebServer(getSelfInitializer())
createWebServer = this.getApplicationStartup().start(\"spring.boot.webserver.create\")
beanFactory.addBeanPostProcessor(new WebApplicationContextServletContextAwareProcessor(this))
0 条评论
下一页