You see FIG SpringBoot a autowiring
SpringBoot from shallow to deep
-
Build springboot environment, it is very simple! How does not require configuration file, just like a guide, run up and get away!
-
@SpringBootApplication comment
-
There is only one class guided comment @SpringBootApplication notes , from the inside to see there are three important notes
-
@SpringBootConfiguration comment
- See equivalents from source @Configuration, i.e., labeling of such a configuration is based Spring
-
@ComponentScan comment
- After learning spring, this is very simple. Notes that scan
- Under the current class scanning package, @ the Controller / Service @ / @ the Component / @ Repository and other notes
-
@EnableAutoConfiguration comment
- @AutoConfigurationPackage Note: Automatic configuration package
- Which still rely on @Import notes , annotations scanning work.
- @Import Note: to import container assembly IOC
- Value FACTORIES_RESOURCE_LOCATION the META-INF / spring.factories
- Spring will start when scanning in all jar path META-INF / spring.factories , the package file into its Properties object
- Properties acquired from the object to the key value EnableAutoConfiguration data, and then added to the container inside.
- @AutoConfigurationPackage Note: Automatic configuration package
-
to sum up
@SpringBootApplication equivalent to the following three notes:
- @SpringBootConfiguration
- @EnableAutoConfiguration
- @ComponentScan
these three notes, which is the key @EnableAutoConfiguration notes, is to start automatically configured. Internal actual @Import annotations , loading META-INF / spring.factories information file, and then screened to EnableAutoConfiguration as key data, is loaded into the vessel IOC, automatic configuration feature!
Reproduced in: https: //juejin.im/post/5cfdbe6c6fb9a07ece67c3dc