what is automatic configuration
In the past, when integrating the spring + mybatis framework, it was necessary to add a lot of beans, such as sqlSessionFactory, etc.
Now that springboot has done it for us, we only need to introduce the corresponding starter.
springBoot can help us configure some beans. Such as mysql, mogondb related operations, etc., there are currently more than 100.
We don't need to import one by one:
A single import is too inefficient.
How to achieve batch import?
@import(AutoConfigurationImportSelector.class)
imports the configuration class collection through the AutoConfigurationImportSelector.selectImports method.
Of course, there can also be configuration classes in other jars, not necessarily all in the starter.
It is necessary to actively tell springBoot in other jars, indicating that it is a configuration class: the file path is meta-inf/spirng.factories
find steps
1 jar find file
meta-inf/spirng.factories
2 find the key
values is a configuration class.
4 Deduplication
5 classLoader loads the class - find the automatic configuration class name
6 Filter irrelevant configuration classes
First look at the dependencies, see if there are any in the pom, and then see if there are key classes.
There are 135 configuration classes, many irrelevant configuration classes,
Through the spring-autoconfigure-metadata.propertes file
First other jvm, start the spring container, resulting in slower speed.
other
After springBoot3.0, the gravVM technology is used, and beans are scanned out at compile time. When starting later, directly register and load the bean, no need to scan again