spring boot SpringApplication.run execution

 

SpringApplication static run(Object source, String... args)

-> new new SpringApplication (Sources) .run (args);
-> SpringApplication.initialize (Object [] Sources);
-> deduceWebEnvironment (), check { "javax.servlet.Servlet", "org.springframework.web.context. ConfigurableWebApplicationContext "} if there is, if there is a web environment, otherwise it is not a web environment
-> ClassUtils.isPresent (String className, ClassLoader classLoader); // the Check class, default classLoader iS null
-> ClassUtils.forName (String name, ClassLoader classLoader ) throws a ClassNotFoundException, a LinkageError; // Load class
-> type atomic map, the common name class cache check whether there exist is returned, otherwise check whether the array, if the array is an array then take the forName inner name called recursively, otherwise the class loader to load the class
-> instance by getSpringFactoriesInstances interface initialization ApplicationContextInitializer
-> SpringFactoriesLoader.loadFactoryNames (type, classLoader) ); according to the type of loading, reading FACTORIES_RESOURCE_LOCATION = "META-INF / spring.factories " resources, called "META-INF / spring.factories" There are many,
scanning related package, package contains ApplicationContextInitializer been found, and finally in the
jar: file: / D: /Users/jwlv/.m2/repository/org/springframework/boot/spring-boot/1.5.16.RELEASE/spring-boot-1.5.16 . RELEASE.jar! /META-INF/spring.factories found the following properties

0 = {Hashtable$Entry@1897} "org.springframework.boot.diagnostics.FailureAnalyzer" -> "org.springframework.boot.diagnostics.analyzer.BeanCurrentlyInCreationFailureAnalyzer,org.springframework.boot.diagnostics.analyzer.BeanNotOfRequiredTypeFailureAnalyzer,org.springframework.boot.diagnostics.analyzer.BindFailureAnalyzer,org.springframework.boot.diagnostics.analyzer.ConnectorStartFailureAnalyzer,org.springframework.boot.diagnostics.analyzer.NoSuchMethodFailureAnalyzer,org.springframework.boot.diagnostics.analyzer.NoUniqueBeanDefinitionFailureAnalyzer,org.springframework.boot.diagnostics.analyzer.PortInUseFailureAnalyzer,org.springframework.boot.diagnostics.analyzer.ValidationExceptionFailureAnalyzer"
1 = {Hashtable$Entry@1898} "org.springframework.boot.env.EnvironmentPostProcessor" -> "org.springframework.boot.cloud.CloudFoundryVcapEnvironmentPostProcessor,org.springframework.boot.env.SpringApplicationJsonEnvironmentPostProcessor"
2 = {Hashtable$Entry@1899} "org.springframework.boot.SpringApplicationRunListener" -> "org.springframework.boot.context.event.EventPublishingRunListener"
3 = {Hashtable$Entry@1900} "org.springframework.context.ApplicationContextInitializer" -> "org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer,org.springframework.boot.context.ContextIdApplicationContextInitializer,org.springframework.boot.context.config.DelegatingApplicationContextInitializer,org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer"
4 = {Hashtable$Entry@1901} "org.springframework.boot.env.PropertySourceLoader" -> "org.springframework.boot.env.PropertiesPropertySourceLoader,org.springframework.boot.env.YamlPropertySourceLoader"
5 = {Hashtable$Entry@1902} "org.springframework.context.ApplicationListener" -> "org.springframework.boot.ClearCachesApplicationListener,org.springframework.boot.builder.ParentContextCloserApplicationListener,org.springframework.boot.context.FileEncodingApplicationListener,org.springframework.boot.context.config.AnsiOutputApplicationListener,org.springframework.boot.context.config.ConfigFileApplicationListener,org.springframework.boot.context.config.DelegatingApplicationListener,org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener,org.springframework.boot.logging.ClasspathLoggingApplicationListener,org.springframework.boot.logging.LoggingApplicationListener"
6 = {Hashtable$Entry@1903} "org.springframework.boot.diagnostics.FailureAnalysisReporter" -> "org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter"

加载3 = {Hashtable$Entry@1900} "org.springframework.context.ApplicationContextInitializer"中的四个类

在jar:file:/D:/Users/jwlv/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.5.16.RELEASE/spring-boot-autoconfigure-1.5.16.RELEASE.jar!/META-INF/spring.factories

0 = {Hashtable$Entry@2121} "org.springframework.boot.autoconfigure.AutoConfigurationImportFilter" -> "org.springframework.boot.autoconfigure.condition.OnClassCondition"
1 = {Hashtable$Entry@2122} "org.springframework.boot.diagnostics.FailureAnalyzer" -> "org.springframework.boot.autoconfigure.diagnostics.analyzer.NoSuchBeanDefinitionFailureAnalyzer,org.springframework.boot.autoconfigure.jdbc.DataSourceBeanCreationFailureAnalyzer,org.springframework.boot.autoconfigure.jdbc.HikariDriverConfigurationFailureAnalyzer"
2 = {Hashtable$Entry@2123} "org.springframework.boot.autoconfigure.AutoConfigurationImportListener" -> "org.springframework.boot.autoconfigure.condition.ConditionEvaluationReportAutoConfigurationImportListener"
3 = {Hashtable$Entry@2124} "org.springframework.context.ApplicationContextInitializer" -> "org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer,org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer"
4 = {Hashtable$Entry@2125} "org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider" -> "org.springframework.boot.autoconfigure.freemarker.FreeMarkerTemplateAvailabilityProvider,org.springframework.boot.autoconfigure.mustache.MustacheTemplateAvailabilityProvider,org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider,org.springframework.boot.autoconfigure.thymeleaf.ThymeleafTemplateAvailabilityProvider,org.springframework.boot.autoconfigure.web.JspTemplateAvailabilityProvider"
5 = {Hashtable$Entry@2126} "org.springframework.context.ApplicationListener" -> "org.springframework.boot.autoconfigure.BackgroundPreinitializer"
6 = {Hashtable$Entry@2127} "org.springframework.boot.autoconfigure.EnableAutoConfiguration" -> "org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration,org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration,org.springframework.boot.autoconfigure.cloud.CloudAutoConfiguration,org.springframework.boot.autoconfigure.context.ConfigurationPropertiesAutoConfiguration,org.springframework.boot.autoconfigure.context.MessageSourceAutoConfiguration,org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration,org.springframework.boot.autoconfigure.couchbase.CouchbaseAutoConfiguration,org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration,org.springfra

加载3 = {Hashtable$Entry@2124} "org.springframework.context.ApplicationContextInitializer" 中的两个类

最终返回下面6个类名,需要被初始化
0 = "org.springframework.boot.context.ConfigurationWarningsApplicationContextInitializer"
1 = "org.springframework.boot.context.ContextIdApplicationContextInitializer"
2 = "org.springframework.boot.context.config.DelegatingApplicationContextInitializer"
3 = "org.springframework.boot.context.embedded.ServerPortInfoApplicationContextInitializer"
4 = "org.springframework.boot.autoconfigure.SharedMetadataReaderFactoryContextInitializer"
5 = "org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer"
->createSpringFactoriesInstances above class name returned collection is instantiated, the present SpringApplication.initializers

-> Example ApplicationListener interface initialization, the process of Example initializer Similarly, at the last instantiated listener, in the presence of SpringApplication.listeners
0 = "org.springframework.boot.ClearCachesApplicationListener"
. 1 = "org.springframework.boot.builder.ParentContextCloserApplicationListener "
2 =" org.springframework.boot.context.FileEncodingApplicationListener "
. 3 =" org.springframework.boot.context.config.AnsiOutputApplicationListener "
. 4 =" org.springframework.boot.context.config.ConfigFileApplicationListener "
. 5 =" org.springframework .boot.context.config.DelegatingApplicationListener "
. 6 =" org.springframework.boot.liquibase.LiquibaseServiceLocatorApplicationListener "
. 7 =" org.springframework.boot.logging.ClasspathLoggingApplicationListener"
=. 8 "org.springframework.boot.logging.LoggingApplicationListener"
. 9 = "org.springframework.boot.autoconfigure.BackgroundPreinitializer"

-> deduceMainApplicationClass () inferred main class, by obtaining the stack frame listing new RuntimeException () getStackTrace (), to find. main methods.

-> SpringApplication.run (String ... args)
-> by example getSpringFactoriesInstances initialization SpringApplicationRunListener interface (org.springframework.boot.context.event.EventPublishingRunListener) and starts,
initialization environmental information new StandardServletEnvironment (),

processing banner, is to start screen,

instantiation context ConfigurableApplicationContext the web environment according to instantiate org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext,
or instantiated according org.springframework.context.annotation.AnnotationConfigApplicationContext,

initialization FailureAnalyzers, for analysis,

the foregoing initialization the configuration information prepared on-line text prepareContext (ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners,
ApplicationArguments applicationArguments, Banner printedBanner), wherein context.setEnvironment (environment) initializes the ApplicationContext, the MessageSource, LifecycleProcessor, the ApplicationEventMulticaster,
ResourcePatternResolver, the BeanFactoryPostProcessor, applicationListeners, ConfigurableListableBeanFactory
applyInitializers (context) in the context of the initializer,
context.getBeanFactory (). RegisterSingleton ( " springApplicationArguments ", applicationArguments) spring loading the bean special one embodiment,
examples of BeanDefinitionLoader, containing sources, annotatedReader, xmlReader, scanner, groovyReader attribute for reading various types of configuration, configured to run various types of loading,
loaded for initialization of SpringBootServletInitializer the configuration of the subclass.

The context parameter refresh prepared refreshContext (context), and some of the underlying common initialization context the bean, the call AbstractApplicationContext OnRefresh () method, and then create the container by createEmbeddedServletContainer (),
Which will be used tomcatEmbeddedServletContainerFactory.
Bean initialization time, there will be a mergedBean concepts, such as, first of all have a Bean A, A initialization time, there are no checks A parent, then the parent will be merged into A and mergedBean b, then b recursively until the process before no dependence, the process will initialize the other attributes if a single embodiment,
if one of the bean comprises a non-single in a bean b in the embodiment, it is not a single case.
Finally, in onRefresh () will start tomcat.
Then finishBeanFactoryInitialization (beanFactory) method initializes other non-lazy-init of bean, bean name will first traverse so the list of registered
returns the context.






















Guess you like

Origin www.cnblogs.com/lvjianwei/p/11225895.html