1 Detailed source code process
Click on the note: @SpringBootApplication
the main entrance of the program.
Note: @SpringBootConfiguration @EnableAutoConfiguration
special note: @EnableAutoConfiguration
automatically import the configuration.
Click on the note: @EnableAutoConfiguration
note: @Import(AutoConfigurationImportSelector.class)
note: List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);
candidate configuration.
Click: loadFactoryNames
note: FACTORIES_RESOURCE_LOCATION
get:public static final String FACTORIES_RESOURCE_LOCATION = "META-INF/spring.factories";
2 How the configuration file operates
In spring.factories
, we find the launcher and org.springframework.boot.autoconfigure.web.servlet.HttpEncodingAutoConfiguration,\
enter HttpEncodingAutoConfiguration
it to see the
automatic binding properties. @EnableConfigurationProperties(ServerProperties.class)
Click to see.
We can application.yaml
modify it through the configuration file .
Click private final Encoding encoding = new Encoding();
to get the
configuration file. What can be written? What is the connection with spring.factories?
xxxAutoConfiguration: The default value of xxxProperties is bound to the configuration file, and I can use a custom configuration.
一但这个配置类生效;这个配置类就会给容器中添加各种组件;
这些组件的属性是从对应的properties类中获取的,这些类里面的每一个属性又是和配置文件绑定的;
所有在配置文件中能配置的属性都是在xxxxProperties类中封装着;
配置文件能配置什么就可以参照某个功能对应的这个属性类
1. SpringBoot will load a large number of automatic configuration classes.
2. Let's see if the functions we need are in the automatic configuration classes written by SpringBoot by default;
3. Let's look at which components are configured in this automatic configuration class; (as long as The components we want to use exist in it, so we don't need to configure them manually)
4. When adding components to the container's automatic configuration class, certain properties will be obtained from the properties class. We only need to specify the value of these properties in the configuration file;
xxxxAutoConfigurartion: automatic configuration class; add components to the container
xxxxProperties: package the relevant properties in the configuration file;