SpringBoot自动装配原理

Posted by     "刘晓疆" on Wednesday, June 28, 2023

SpringBoot自动装配原理

@SpringBootConfiguration

在SpringBootConfiguration类下主要有以下注解

@org.springframework.boot.SpringBootConfiguration
@org.springframework.boot.autoconfigure.EnableAutoConfiguration
@org.springframework.context.annotation.ComponentScan

SpringBootConfiguration

进入注解可以发现

自动装配本质

SpringBoot自动装配的本质就是通过Spring去读取META-INF/spring.factories中保存的配置类文件然后加载bean定义的过程(借助javaConfig类来获取文件)。 如果是标了@Configuration注解,就是批量加载了里面的bean定义 如何实现 “自动”:通过配置文件获取对应的批量配置类,然后通过配置类批量加载bean定义,只要有写好的配置文件spring.factories就实现了自动。

总结

SpringBoot的自动装配特性可以说是Spring Boot最重要、最核心的一环,正是因为这个特性,使得我们的生产复杂性大大降低,极大地简化了开发流程。

「真诚赞赏,手留余香」

Xiaojiang Blog

真诚赞赏,手留余香

使用微信扫描二维码完成支付