Automatically.

1. The @SpringBootApplication annotation is parsed when the program executes

2. Click on annotations

4. Point into @ EnableAutoConfiguration

5. Point into AutoConfigurationImportSelector

On the surface, pick some classes related to autowiring

6. Turn down

7. Point into this. GetCandidateConfigurations (annotationMetadata, attributes);

Where did you get it

That’s what came in

8 points into loadFactoryNames

Go back to Step 6

Summary: Spring automatically scans the meta-INF/Spring. factories file on all classpath and loads them into the cache

thinking

For example, why is JDBC auto-assembled

1. In the spring. The key under the factories for org. Springframework. Boot. Autoconfigure. EnableAutoConfiguration

3. Peruse the above category

Summary:

Write your own auto assembly how to write

Create a meta-info /spring.factories home key and value for the class you want to inject into your classpath

Write a Properties class and put some configuration information

Inject the Properties class into a class like injection

It’s good

They have their own list

Mybatis is not included in the built-in list

Let’s start with Mybatis

Configuration Information class

Automatic assembly class

A brief summary of automatic assembly

  1. When Spring calls the run method, it takes all the spring.factories from meta-info in the classpath and stores them in the cache
  2. The EnableAutoConfiguration annotation takes the data from the cache and filters it, leaving a number of values corresponding to the EnableAutoConfiguration key
  3. All classes corresponding to these values will be loaded into the container for automatic assembly