[Java development framework SpringBoot] @SpringBootApplication annotation details

@SpringBootApplication Detailed

The SpringBoot application annotation on a certain class indicates that this class is the main configuration class of SpringBoot, and SpringBoot should run the main method of this class to start the SpringBoot application.

View @SpringBootApplication source code

Insert picture description here
The first four annotations: meta-annotations, used to modify the current annotations, just like the modifiers of the public class, they have no actual function.

1、@SpringBootConfiguration: SpringBoot configuration class

Mark on a certain class, indicating that this is a SpringBoot configuration class. @SpringBootConfiguration inherits from @Configuration, the functions of the two are also the same, marking the current class as a configuration class, and will include one or more instances of methods declared in the current class marked with @Bean annotations into the container, and the instance name is Method name.

2、@EnableAutoConfiguration: Turn on the automatic configuration function. With the automatic configuration class, it saves us the work of manually writing configuration injection functional components.

What we need to configure before, SpringBoot will automatically configure it for us. @EnableAutoConfiguration tells SpringBoot to enable the automatic configuration function so that the automatic configuration can take effect.

View @EnableAutoConfiguration source code

Insert picture description here
@AutoConfigurationPackage: Scan all components in the package of the main configuration class (class marked by @SpringBootApplication) and all sub-packages below into the container.

@Import(AutoConfigurationImportSelector.class): Spring's low-level annotations, import components to the container.

AutoConfigurationImportSelector: A selector of which components to import.
With the help of AutoConfigurationImportSelector, @EnableAutoConfiguration can help SpringBoot applications load all eligible configurations into the container created and used by SpringBoot in the form of full class names.

Insert picture description here

When SpringBoot starts, it obtains the values ​​specified by EnableAutoConfiguration from META-INF/spring.factories under the classpath, and loads these values ​​into the container as an auto-configuration class, and the auto-configuration takes effect and helps us with the auto-configuration work.

Insert picture description here
J2EE's overall integration solution and automatic configuration are all under this package.

3、@ComponentScan: Automatically scan components, that is, tell spring where to scan for beans.

Use annotations on classes, such as @Controller, @Component, @Configuration and other annotations. @ComponentScan will scan the classes with these annotations and load them into the container.

to sum up

如果觉得不错,可以点赞+收藏或者关注下博主。感谢阅读!

Guess you like

Origin blog.csdn.net/weixin_42825651/article/details/109197425
Recommended