See SpringBoot automatic assembly from source

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
        1. Value FACTORIES_RESOURCE_LOCATION the META-INF / spring.factories
        2. Spring will start when scanning in all jar path META-INF / spring.factories , the package file into its Properties object
        3. Properties acquired from the object to the key value EnableAutoConfiguration data, and then added to the container inside.

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

Guess you like

Origin blog.csdn.net/weixin_34375233/article/details/91465494