Automatic configuration module SpringBoot
The configuration module is primarily used to SpringFactoriesLoader
, i.e. Spring plant loader, the object provides a loadFactoryNames
method, 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.factories
files, 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 loadFactoryNames
method 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-web
The META-INF files components contain spring.factories
files, automatic configuration module, SpringFactoriesLoader
to 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 EnableAutoConfiguration
notes, 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 AutoConfigurationImportSelector
the selectImports
method.