2023.02.08 SpringBoot启动流程
2023-03-27 21:28:09 16 举报
SpringBoot启动流程
作者其他创作
大纲/内容
AbstractAutowireCapableBeanFactory
onRefresh
springApplicationCommandLineArgs
applyInitializers
Spring容器中的实现Ordered接口的BeanFactoryPostProcessor
props = {Properties@2078} size = 62 \"java.runtime.name\" -> \"Java(TM) SE Runtime Environment\" \"spring.output.ansi.enabled\" -> \"always\" \"sun.boot.library.path\" -> \"/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib\" \"java.vm.version\" -> \"25.351-b10\" \"gopherProxySet\" -> \"false\" \"java.vm.vendor\" -> \"Oracle Corporation\" \"java.vendor.url\" -> \"http://java.oracle.com/\" \"java.rmi.server.randomIDs\" -> \"true\" \"path.separator\" -> \":\" \"java.vm.name\" -> \"Java HotSpot(TM) 64-Bit Server VM\" \"file.encoding.pkg\" -> \"sun.io\" \"user.country\" -> \"CN\" \"sun.java.launcher\" -> \"SUN_STANDARD\" \"sun.os.patch.level\" -> \"unknown\" \"java.vm.specification.name\" -> \"Java Virtual Machine Specification\" \"user.dir\" -> \"/Users/tec/project/spring-cloud-demo\" \"intellij.debug.agent\" -> \"true\" \"java.runtime.version\" -> \"1.8.0_351-b10\" \"java.awt.graphicsenv\" -> \"sun.awt.CGraphicsEnvironment\" \"java.endorsed.dirs\" -> \"/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/endorsed\" \"os.arch\" -> \"x86_64\" \"java.io.tmpdir\" -> \"/var/folders/pm/zb_l38g90hg3fkmdyg6cfyk80000gp/T/\" \"line.separator\" -> \"\\" \"java.vm.specification.vendor\" -> \"Oracle Corporation\" \"os.name\" -> \"Mac OS X\" \"sun.jnu.encoding\" -> \"UTF-8\" \"java.library.path\" -> \"/Users/tec/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.\" \"jboss.modules.system.pkgs\" -> \"com.intellij.rt\" \"spring.jmx.enabled\" -> \"true\" \"java.specification.name\" -> \"Java Platform API Specification\" \"java.class.version\" -> \"52.0\" \"sun.management.compiler\" -> \"HotSpot 64-Bit Tiered Compilers\" \"spring.liveBeansView.mbeanDomain\" -> \"\" \"os.version\" -> \"12.6.1\" \"user.home\" -> \"/Users/tec\" \"user.timezone\" -> \"Asia/Shanghai\" \"java.awt.printerjob\" -> \"sun.lwawt.macosx.CPrinterJob\" \"file.encoding\" -> \"UTF-8\" \"java.specification.version\" -> \"1.8\" \"java.class.path\" -> \"/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVir\" \"user.name\" -> \"tec\" \"com.sun.management.jmxremote\" -> \"\" \"java.vm.specification.version\" -> \"1.8\" \"sun.java.command\" -> \"tech.tecchen.cloud.ProviderApplication\" \"java.home\" -> \"/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre\" \"sun.arch.data.model\" -> \"64\" \"user.language\" -> \"zh\" \"java.specification.vendor\" -> \"Oracle Corporation\" \"awt.toolkit\" -> \"sun.lwawt.macosx.LWCToolkit\" \"java.vm.info\" -> \"mixed mode\" \"java.version\" -> \"1.8.0_351\" \"java.ext.dirs\" -> \"/Users/tec/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java\" \"sun.boot.class.path\" -> \"/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_351.jdk/Contents/Home/jre/classes\" \"java.awt.headless\" -> \"true\" \"java.vendor\" -> \"Oracle Corporation\" \"java.specification.maintenance.version\" -> \"4\" \"spring.application.admin.enabled\" -> \"true\" \"file.separator\" -> \"/\" \"java.vendor.url.bug\" -> \"http://bugreport.sun.com/bugreport/\" \"sun.io.unicode.encoding\" -> \"UnicodeBig\" \"sun.cpu.endian\" -> \"little\" \"sun.cpu.isalist\" -> \"\"
postProcessBeanFactory
finishBeanFactoryInitialization
prepareBeanFactory
beanFactoryPostProcessors
systemProperties
prepareRefresh
0 = {DelegatingApplicationContextInitializer@3956} 1 = {SharedMetadataReaderFactoryContextInitializer@3957} 2 = {ContextIdApplicationContextInitializer@3958} 3 = {TestApplicationContextInitializer@3959} 4 = {ConfigurationWarningsApplicationContextInitializer@3960} 5 = {RSocketPortInfoApplicationContextInitializer@3961} 6 = {ServerPortInfoApplicationContextInitializer@3962} 7 = {ConditionEvaluationReportLoggingListener@3963}
ConfigurationPropertySources.attach(environment)
0 = {EnvironmentPostProcessorApplicationListener@2223} 1 = {AnsiOutputApplicationListener@2224} 2 = {LoggingApplicationListener@1895} 3 = {BackgroundPreinitializer@1896} 4 = {DelegatingApplicationListener@1897} 5 = {TestApplicationListener@1898} 6 = {FileEncodingApplicationListener@2225}
primarySources、webApplicationType、mainApplicationClass
resolvableDependencies = {ConcurrentHashMap@3921} size = 4 {Class@2791} \"interface org.springframework.context.ApplicationContext\" {Class@2786} \"interface org.springframework.beans.factory.BeanFactory\" {Class@2079} \"interface org.springframework.core.io.ResourceLoader\" {Class@2790} \"interface org.springframework.context.ApplicationEventPublisher\"
Spring容器中的未实现以上两个接口的BeanDefinitionRegistryPostProcessor
servletConfigInitParams
initMessageSource
new SpringApplication
ConfigurablePropertyResolver configurationPropertySourcesPropertyResolver = ConfigurationPropertySources.createPropertyResolver(propertySources)
initApplicationEventMulticaster
ApplicationEnvironmentPreparedEvent
ServletWebServerApplicationContext#createWebServer
AbstractApplicationContextResourcePatternResolver resourcePatternResolver = new ServletContextResourcePatternResolver
https://blog.csdn.net/BlackReimu/article/details/123863330
0 = {RandomValuePropertySourceEnvironmentPostProcessor@2727} 1 = {SystemEnvironmentPropertySourceEnvironmentPostProcessor@2728} 2 = {SpringApplicationJsonEnvironmentPostProcessor@2729} 3 = {CloudFoundryVcapEnvironmentPostProcessor@2730} 4 = {ConfigDataEnvironmentPostProcessor@2731} 5 = {DebugAgentEnvironmentPostProcessor@2732} 6 = {IntegrationPropertiesEnvironmentPostProcessor@2733}
0 = {EnvironmentPostProcessorApplicationListener@4063} 1 = {AnsiOutputApplicationListener@4069} 2 = {LoggingApplicationListener@4070} 3 = {BackgroundPreinitializer@4071} 4 = {DelegatingApplicationListener@4072} 5 = {ParentContextCloserApplicationListener@4073} 6 = {ClearCachesApplicationListener@4074} 7 = {FileEncodingApplicationListener@4075}
Spring容器中的实现PriorityOrdered接口的BeanDefinitionRegistryPostProcessor
callRunners
obtainFreshBeanFactory
BeanPostProcessor
registerListeners
initializers = getSpringFactoriesInstances(ApplicationContextInitializer.class)
last-defaultProperties
ConfigurableApplicationContext context = createApplicationContext()
SpringFactoriesLoader.loadFactoryNames(SpringApplicationRunListener.class)
commandLineArgs
configurePropertySources
listeners.contextLoaded(context)ApplicationPreparedEvent
所有BeanFactoryPostProcessor
registerBeanPostProcessors
resolvableDependencies
listeners = getRunListeners
listeners = getSpringFactoriesInstances(ApplicationListener.class)
Spring容器中的未实现以上两个接口的BeanPostProcessor
BootstrapRegistryInitializer.initialize()
Spring容器中的实现PriorityOrdered接口的BeanPostProcessor
ConfigurableConversionService conversionService = new ApplicationConversionService()
afterRefresh
GenericApplicationContextbeanFactory = new DefaultListableBeanFactory
postProcessBeanDefinitionRegistry
AbstractAutowireCapableBeanFactory.allowCircularReferences循环引用【Spring默认true,SpringBoot默认false】
run
first-configurationProperties
ignoredDependencyInterfaces
configureProfiles
jndiProperties
random
Spring容器中的实现PriorityOrdered接口的BeanFactoryPostProcessor
BootstrapContextClosedEvent
preInstantiateSingletons实例化所有剩余的单例Bean
0 = {LoggingApplicationListener@1895} 1 = {BackgroundPreinitializer@1896} 2 = {DelegatingApplicationListener@1897} 3 = {TestApplicationListener@1898} 4 = {TestApplicationStartingEventApplicationListener@1899}
BeanDefinitionRegistryPostProcessor实例
BeanFactoryPostProcessor
⭐️2023.04.23 SpringBoot自动配置源码解析https://www.processon.com/view/link/6444f93b84b4b71c14ff3fa3
DefaultListableBeanFactory.allowBeanDefinitionOverriding重写Bean定义【Spring默认true,SpringBoot默认false】
logStartupInfologStartupProfileInfo
ApplicationStartingEvent
prepareContext
LazyInitializationBeanFactoryPostProcessorPropertySourceOrderingBeanFactoryPostProcessor
DefaultPropertiesPropertySource.moveToEnd(environment)
AnnotationConfigServletWebServerApplicationContextreader = new AnnotatedBeanDefinitionReaderscanner = new ClassPathBeanDefinitionScannerAnnotationConfigReactiveWebServerApplicationContext
BeanDefinitionRegistry
getBeanPostProcessors() = {AbstractBeanFactory$BeanPostProcessorCacheAwareList@3958} size = 3 0 = {ApplicationContextAwareProcessor@3959} 1 = {ApplicationListenerDetector@4359} 2 = {WebApplicationContextServletContextAwareProcessor@4289}
Spring容器中的实现Ordered接口的BeanDefinitionRegistryPostProcessor
ApplicationServletEnvironment = getOrCreateEnvironment
MutablePropertySources propertySources
不是BeanDefinitionRegistryPostProcessor实例的BeanFactoryPostProcessor
Spring容器中的未实现以上两个接口的BeanFactoryPostProcessor
source = {Collections$UnmodifiableMap@2477} size = 17 \"__CFBundleIdentifier\" -> \"com.jetbrains.intellij\" \"PATH\" -> \"/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Library/Apple/usr/bin:/Users/tec/apache-maven-3.8.6/bin\" \"SHELL\" -> \"/bin/zsh\" \"OLDPWD\" -> \"/\" \"USER\" -> \"tec\" \"COMMAND_MODE\" -> \"unix2003\" \"TMPDIR\" -> \"/var/folders/pm/zb_l38g90hg3fkmdyg6cfyk80000gp/T/\" \"SSH_AUTH_SOCK\" -> \"/private/tmp/com.apple.launchd.ovitpszAbd/Listeners\" \"XPC_FLAGS\" -> \"0x0\" \"M2_HOME\" -> \"/Users/tec/apache-maven-3.8.6\" \"__CF_USER_TEXT_ENCODING\" -> \"0x1F6:0x19:0x34\" \"LOGNAME\" -> \"tec\" \"LC_CTYPE\" -> \"zh_CN.UTF-8\" \"PWD\" -> \"/Users/tec/project/spring-cloud-demo\" \"XPC_SERVICE_NAME\" -> \"application.com.jetbrains.intellij.89746.90587\" \"JAVA_MAIN_CLASS_2768\" -> \"tech.tecchen.cloud.ProviderApplication\" \"HOME\" -> \"/Users/tec\"
bootstrapContext=createBootstrapContext
0 = {BackgroundPreinitializer@1896} 1 = {DelegatingApplicationListener@1897} 2 = {TestApplicationListener@1898}
ignoredDependencyInterfaces = {HashSet@3931} size = 10 0 = {Class@1749} \"interface org.springframework.beans.factory.BeanFactoryAware\" 1 = {Class@3420} \"interface org.springframework.context.EnvironmentAware\" 2 = {Class@4021} \"interface org.springframework.context.ApplicationEventPublisherAware\" 3 = {Class@4022} \"interface org.springframework.context.MessageSourceAware\" 4 = {Class@3254} \"interface org.springframework.context.ApplicationStartupAware\" 5 = {Class@1676} \"interface org.springframework.context.ApplicationContextAware\" 6 = {Class@2934} \"interface org.springframework.context.ResourceLoaderAware\" 7 = {Class@1863} \"interface org.springframework.context.EmbeddedValueResolverAware\" 8 = {Class@3488} \"interface org.springframework.beans.factory.BeanNameAware\" 9 = {Class@1748} \"interface org.springframework.beans.factory.BeanClassLoaderAware\"
configureEnvironment
Spring容器中的实现Ordered接口的BeanPostProcessor
SystemEnvironmentPropertySourceEnvironmentPostProcessorreplacePropertySource(OriginAwareSystemEnvironmentPropertySource)
systemEnvironment
initializers = {ArrayList@1875} size = 8 0 = {DelegatingApplicationContextInitializer@1878} 1 = {SharedMetadataReaderFactoryContextInitializer@1879} 2 = {ContextIdApplicationContextInitializer@1880} 3 = {TestApplicationContextInitializer@1881} 4 = {ConfigurationWarningsApplicationContextInitializer@1882} 5 = {RSocketPortInfoApplicationContextInitializer@1883} 6 = {ServerPortInfoApplicationContextInitializer@1884} 7 = {ConditionEvaluationReportLoggingListener@1885}
finishRefresh
beanFactoryPostProcessors = {ArrayList@3257} size = 3 0 = {SharedMetadataReaderFactoryContextInitializer$CachingMetadataReaderFactoryPostProcessor@3971} 1 = {ConfigurationWarningsApplicationContextInitializer$ConfigurationWarningsPostProcessor@3972} 2 = {SpringApplication$PropertySourceOrderingBeanFactoryPostProcessor@3973}
bootstrapRegistryInitializers = new ArrayList<>(getSpringFactoriesInstances(BootstrapRegistryInitializer.class))
postProcessApplicationContext
this.bootstrapRegistryInitializers = {ArrayList@1831} size = 1 0 = {TestBootstrapRegistryInitializer@1833}
refreshContext
ApplicationContextInitializedEvent
invokeBeanFactoryPostProcessors
servletContextInitParams
0 条评论
下一页