当前位置: 首页 > news >正文

SpringBoot自动装配

自动装配就是自动地把其他组件中的Bean装载到IOC容器中,不需要开发人员再去配置文件中添加大量的配置

源码分析

@EnableAutoConfigurationSpringBoot实现自动化配置的核心注解

 AutoConfigurationImportSelector类分析

public class AutoConfigurationImportSelector...{...protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {List<String> configurations = new ArrayList<>(SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(), getBeanClassLoader()));ImportCandidates.load(AutoConfiguration.class, getBeanClassLoader()).forEach(configurations::add);Assert.notEmpty(configurations,//扫描"No auto configuration classes found in META-INF/spring.factories nor in META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports. If you "+ "are using a custom packaging, make sure that file is correct.");return configurations;}
}

条件装配

并不是读取到的所有的配置类中Bean都会被初始化,在配置类中使用@Condition来加载满足条件的Bean

  •  ConditionalOnClass:      判断环境中是否有对应字节码文件才初始化Bean
  •  ConditionalOnProperty:   判断配置文件中是否有对应属性和值才初始化Bean 
  •  ConditionalOnMissingBean:判断环境中没有对应Bean才初始化Bean

http://www.xdnf.cn/news/168643.html

相关文章:

  • pytorch搭建并训练神经网络
  • C++ 基于多设计模式下的同步异步⽇志系统-2项目实现
  • 【网络原理】从零开始深入理解TCP的各项特性和机制.(二)
  • git回退commit
  • 如何打包一个QT 程序
  • rockermq多线程消费者配置
  • Android——RecyclerView
  • Qt 中 QSQLITE 和 QODBC 数据库连接的区别
  • CentOS7.9安装OpenSSL 1.1.1t和OpenSSH9.9p1
  • 常用描述性统计 - AxureMost
  • 【网络原理】从零开始深入理解TCP的各项特性和机制.(三)
  • Linux命令#文件操作
  • 基于Pytest接口自动化的requests模块项目实战以及接口关联方法详解
  • ubuntu 安装ollama后,如何让外网访问?
  • 《代码整洁之道》第4章 注释 - 笔记
  • Android开发中svg转xml工具使用
  • 微服务基础-Ribbon
  • 2.脚本文件初识
  • 基于单片机的智能药盒系统
  • 【Azure Redis 缓存】在Azure Redis中,如何限制只允许Azure App Service访问?
  • 贪心算法-860.柠檬水找零-力扣(LeetCode)
  • 关于OCP认证:有Oracle和MySQL两种
  • 【vue3】购物车实战:从状态管理到用户体验的全流程实现
  • 996引擎-人物模型(UIModel):创建内观时装备偏移问题
  • 「Mac畅玩AIGC与多模态02」部署篇01 - 在 Mac 上部署 Ollama + Open WebUI
  • 云原生--核心组件-容器篇-4-认识Dockerfile文件(镜像创建的基础文件和指令介绍)
  • 深度解析:TextRenderManager——Cocos Creator艺术字体渲染核心类
  • Golang 遇见 Kubernetes:云原生开发的完美结合
  • Kotlin中的also、apply、invoke用法详解
  • 泛型的诗意——深入C++模板的艺术与科学(模版进阶)