1. First of all, you need to know what the springbootApplication annotation does. It is a composite annotation @SpringBootApplication as a collection of @Configuration, @EnableAutoConfiguration, @ComponentScan annotations.
@enableAutoConfiguration: Enable SpringBoot automatic configuration @ComponentScan: Scan beans annotated by @Component (@service,@Controller). By default, the annotation scans all classes in the package in which that class belongs. @Configuration: Allows registering additional beans in context or importing additional Configuration classes 2. Next it will access whether the Application. proporites file exists, load the configuration information in it, and generate the bean, such as the Redis configuration, which will generate the redisTemplate class and inject it. 3. What is the process by which Spring loads beans
-
The Bean container finds the definition of the Spring Bean in the configuration file. The Bean container utilizes the Java Reflection API
-
Create an instance of a Bean. If some attribute values are involved use the set() method to set some attribute values. If the Bean implements the BeanNameAware interface, call the setBeanName() method, passing in the Bean’s name. If the Bean implements the BeanClassLoaderAware interface, call the setBeanClassLoader() method, passing in an instance of the ClassLoader object. Similar to the above, if other *.aware interfaces are implemented, the corresponding methods are called.
-
If you have, and load the Bean Spring container of related objects BeanPostProcessor, perform postProcessBeforeInitialization () method
-
If the Bean implements the InitializingBean interface, execute the afterPropertiesSet() method.
-
If the Bean definition in the configuration file contains the init-method attribute, the specified method is executed.
-
If you have, and load the Bean Spring container of related objects BeanPostProcessor, perform postProcessAfterInitialization () method When to destroy the Bean, If the Bean implements the DisposableBean interface, execute the destroy() method. When it is time to destroy a Bean, execute the specified method if the Bean’s definition in the configuration file contains the destroy-method attribute.
4. Springboot has already implemented automatic configuration, and you will only need a small amount of configuration to complete development.
Github address:github.com/lx-IT-P/
**