SpringBoot (b) start principle

 

 

Automatic configuration module SpringBoot

The configuration module is primarily used to SpringFactoriesLoader, i.e. Spring plant loader, the object provides a loadFactoryNamesmethod, into the reference to factoryClass and classLoader, i.e. it needs to pass the factory class name and the corresponding class loader, a method based on the specified classLoader, loaded adding the class specified file search path , i.e. spring.factoriesfiles, factory class for the incoming interface and the corresponding class file is interface implementation class, or implemented as a final class file so that a generally follows FIG. a set of multi-class name, class name acquired implement these classes, the loadFactoryNamesmethod returns the class name in the collection, the collection of these methods to give the caller, and then acquires these classes class object constructed by a reflection method, finally generated instance.

 

SpringBoot automated configuration key component diagram

mybatis-spring-boot-starter, spring-boot-starter-webThe META-INF files components contain spring.factoriesfiles, automatic configuration module, SpringFactoriesLoaderto collect the class full name of the file and returns an array of the full name of a class, the class returned full name is instantiated by the reflection, the formation of specific examples of the plant, a factory instance bean components generate specific needs.

Before we mentioned EnableAutoConfigurationnotes, its class diagram as follows:

 

It can be found in its final realization of the ImportSelector(selectors) and BeanClassLoaderAware(bean class loader middleware), focus on what AutoConfigurationImportSelectorthe selectImportsmethod.

 

 

 

Guess you like

Origin www.cnblogs.com/fanBlog/p/11126267.html