02--SpringBoot自动装配原理

1、自动配置类读取原理

@SpringBootApplication应用标注在某个类上,说明这个类是SpringBoot的主配置类,SpringBoot的项目需要运行这个类的main方法来启动SpringBoot应用的服务;

1.1 源码分析

java 复制代码
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
 @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
 @Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {}
  • @SpringBootConfiguration:用于标识这个类是SpringBoot的配置类;
  • @EnableAutoConfiguration:开启自动配置的功能,会自动扫描所有自动配置类,扫描到且满足条件才会生效。
  • @ComponentScan:包扫描;
    • TypeExcludeFilter:SpringBoot对外提供的扩展类, 可以去按照我们的方式进行排除
    • AutoConfigurationExcludeFilter:排除所有配置类并且是自动配置类
java 复制代码
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {}
  • @AutoConfigurationPackage:将当前配置类所在包保存在BasePackages的Bean中。供Spring内部使用。
  • 自动装配流程图

后续深入更新...

相关推荐
掉鱼的猫23 分钟前
把 OpenAPI 接入 Agent Harness:零代码让 Agent 听懂你的 REST API
java·llm·agent
lzhcoder27 分钟前
Spring Boot 集成 Kafka:先跑通 Demo,再避开那 80% 的人踩过的坑
java·kafka
plainGeekDev1 小时前
ProGuard → R8
android·java·kotlin
带刺的坐椅1 小时前
把 OpenAPI 接入 Agent Harness:零代码让 Agent 听懂你的 REST API
java·ai·llm·agent·solon·restapi·openapi
Geek-Chow1 小时前
微服务认证与授权:01 — 概念
java·前端·数据库
KobeSacre2 小时前
DelayQueue 源码
java·开发语言
Wang's Blog2 小时前
JavaWeb快速入门: Filter与Listener核心详解
java·filter·listener
zfoo-framework2 小时前
mongodb性能调优 1.从慢查询分析索引 2.掌握索引最左匹配原则!!!
java
AIGS0012 小时前
企业AI落地:从RAG到AgentRAG的技术跃迁
java·人工智能·人工智能ai大模型应用