Spring Boot自动装配原理和源码分析

【源码解析】最详细SpringBoot自动装配原理 Springboot自动配置是指基于你所依赖的Jar包或者maven坐标,对springboot应用进行自动配置,完成第三方bean的注入,达到开箱即用的基础支撑分析SpringBoot自动配置,只能从SpringBoot工程的启动类开始分析启动类可分析的就两个点:run方法和@SpringBootApplication注解在上述递归加载Bean的方法中涉及到两个重要注解,@ComponentScan@Import它的作用是提供一种显式地从其他地方加载配置类的方法,这样可以避免使用性能较差的组件扫描支持导入 阅读详情

该篇的主要内容

  1. Spring Boot的自动装配原理【有案例模拟】
  2. Spring Boot自动装配源码分析

SpringBoot中的自动装载原理

SpringBoot具备开箱即用的特点,它默默的帮我们做了很多事情【自动创建和装配很多对象】

自动装配的实现

主要是通过ImportSelector接口完成的自动装配

ImportSelector

ImportSelector接口是Spring导入外部配置的核心接口,在SpringBoot的自动化配置和@EnableXXX(功能性注解)中起到了决定性的作用。当在@Configuration标注的Class上使用@Import引入了一个 ImportSelector实现类后,会把实现类中返回的Class名称都定义为bean。

package org.springframework.context.annotation;

import org.springframework.core.type.AnnotationMetadata;

public interface ImportSelector {

	/**
	 * Select and return the names of which class(es) should be imported based on
	 * the {@link AnnotationMetadata} of the importing @{@link Configuration} class.
	 */
	String[] selectImports(AnnotationMetadata importingClassMetadata);

} 

该接口的继承关系图

​DeferredImportSelector

由上图可知DeferredImportSelector接口继承自ImportSelector,它和ImportSelector的区别在于装载bean的时机上,DeferredImportSelector需要等所有的@Configuration都执行完毕后才会进行装载。

Spring Boot自动装配案例

项目案例传送门:autoConfig

案例主要代码

  1. 创建一个生产Bean的配置类,但是我们并不使用@Configuration注解来声明它。
public class MyConfig {
    @Bean(value = "chenfu", name = "chenfu")
    public Map<Object, Object> getMap() {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "success");
        String nowDate = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        map.put("data", nowDate);
        return map;
    }
} 

2.实现ImportSelector接口,返回我们上边的配置类名

public class MyConfigImportSelector implements ImportSelector {
    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
//        返回配置名称
        return new String[]{MyConfig.class.getName()};
    }
} 

3.运行测试

@SpringBootApplication
@Import(value = MyConfigImportSelector.class)
public class AutoConfigApp {
    public static void main(String[] args) {
        ConfigurableApplicationContext app = SpringApplication.run(AutoConfigApp.class, args);
        Object chenfu = app.getBean("chenfu");
        System.out.println(chenfu);
    }
} 

案例大体内容如上,通过案例可知经过Spring Boot自动装配的对象并没有使用Spring的对象创建注解声明 (@Controller,@Service,@Repostiroty),而是使用编程的方式动态的载入bean。在Spring Boor中对这些对象的解析步骤主要是在ConfigurationClassParser类的processImports方法内进行的

ImportSelector的解析过程

ConfigurationClassParser

ConfigurationClassParser类的源码

private void processImports(ConfigurationClass configClass, SourceClass currentSourceClass,
		Collection<SourceClass> importCandidates, boolean checkForCircularImports) {
	if (importCandidates.isEmpty()) {
		return;
	}
	if (checkForCircularImports && isChainedImportOnStack(configClass)) {
		this.problemReporter.error(new CircularImportProblem(configClass, this.importStack));
	}
	else {
		this.importStack.push(configClass);
		try {
			for (SourceClass candidate : importCandidates) {
				//对ImportSelector类型的类进行处理
				if (candidate.isAssignable(ImportSelector.class)) {
					// Candidate class is an ImportSelector -> delegate to it to determine imports
					Class<?> candidateClass = candidate.loadClass();
					ImportSelector selector = BeanUtils.instantiateClass(candidateClass, ImportSelector.class);
					ParserStrategyUtils.invokeAwareMethods(
							selector, this.environment, this.resourceLoader, this.registry);
 					//上边我们说过的另外一种Selector类型,可以理解为延迟加载
					if (selector instanceof DeferredImportSelector) {
						//该方法内部会将该Selector保存到一个集合【deferredImportSelectors】中
						this.deferredImportSelectorHandler.handle(
								configClass, (DeferredImportSelector) selector);
					} else {
						String[] importClassNames = selector.selectImports(currentSourceClass.getMetadata());
						Collection<SourceClass> importSourceClasses = asSourceClasses(importClassNames);
						processImports(configClass, currentSourceClass, importSourceClasses, false);
					}
				} else if (candidate.isAssignable(ImportBeanDefinitionRegistrar.class)) {
					// Candidate class is an ImportBeanDefinitionRegistrar ->
					// delegate to it to register additional bean definitions
					Class<?> candidateClass = candidate.loadClass();
					ImportBeanDefinitionRegistrar registrar =
							BeanUtils.instantiateClass(candidateClass, ImportBeanDefinitionRegistrar.class);
					ParserStrategyUtils.invokeAwareMethods(
							registrar, this.environment, this.resourceLoader, this.registry);
					configClass.addImportBeanDefinitionRegistrar(registrar, currentSourceClass.getMetadata());
				} else {
					// Candidate class not an ImportSelector or ImportBeanDefinitionRegistrar ->
					// process it as an @Configuration class
					// 直接把上边的官方英文注释硬翻译了,当前类不是ImportSelector或ImportBeanDefinitionRegistrar类型,直接让其走@Configuration类的处理流程
					this.importStack.registerImport(
							currentSourceClass.getMetadata(), candidate.getMetadata().getClassName());
					processConfigurationClass(candidate.asConfigClass(configClass));
				}
			}
		} catch (BeanDefinitionStoreException ex) {
			throw ex;
		} catch (Throwable ex) {
			throw new BeanDefinitionStoreException(
					"Failed to process import candidates for configuration class [" +
					configClass.getMetadata().getClassName() + "]", ex);
		} finally {
			this.importStack.pop();
		}
	}
} 

综上,大致流程就是ImportSelector接口的返回值会递归进行解析,然后把解析到的类全名最终按照 @Configuration进行处理。

ImportSelector总结

SpringBoot开箱即用的特点,很大程度上归功于ImportSelector。

Spring Boot源码分析

Spring Boot在Spring的基础上做了一些扩展。

  1. 在SpringBoot的SpringBootApplication注解中声明了一个 @EnableAutoConfiguration注解
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(
    excludeFilters = {@Filter(
    type = FilterType.CUSTOM,
    classes = {TypeExcludeFilter.class}
), @Filter(
    type = FilterType.CUSTOM,
    classes = {AutoConfigurationExcludeFilter.class}
)}
)
public @interface SpringBootApplication { 

2.@EnableAutoConfiguration中通过Import引入了SpringBoot定义的@Import({
AutoConfigurationImportSelector.class})

@Import({AutoConfigurationImportSelector.class})
public @interface EnableAutoConfiguration { 

接下来开始对
AutoConfigurationImportSelector进行源码分析

AutoConfigurationImportSelector


AutoConfigurationImportSelector是selectImports的实现类,我们来看selectImports方法

selectImports

public String[] selectImports(AnnotationMetadata annotationMetadata) {
    if (!this.isEnabled(annotationMetadata)) {
        return NO_IMPORTS;
    } else {
        AutoConfigurationMetadata autoConfigurationMetadata = AutoConfigurationMetadataLoader.loadMetadata(this.beanClassLoader);
        AutoConfigurationImportSelector.AutoConfigurationEntry autoConfigurationEntry = this.getAutoConfigurationEntry(autoConfigurationMetadata, annotationMetadata);
        return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
    }
} 

该方法的主要逻辑都在getAutoConfigurationEntry方法内

getAutoConfigurationEntry

protected AutoConfigurationImportSelector.AutoConfigurationEntry getAutoConfigurationEntry(AutoConfigurationMetadata autoConfigurationMetadata, AnnotationMetadata annotationMetadata) {
    if (!this.isEnabled(annotationMetadata)) {
        return EMPTY_ENTRY;
    } else {
        AnnotationAttributes attributes = this.getAttributes(annotationMetadata);
        // 2.1通过getCandidateConfigurations方法获取所有需要加载的bean
        List<String> configurations = this.getCandidateConfigurations(annotationMetadata, attributes);
        // 去重
        configurations = this.removeDuplicates(configurations);
        // 获取不需要加载的bean,我们可以通过spring.autoconfigure.exclude配置
        Set<String> exclusions = this.getExclusions(annotationMetadata, attributes);
        this.checkExcludedClasses(configurations, exclusions);
        configurations.removeAll(exclusions);
        configurations = this.filter(configurations, autoConfigurationMetadata);
        // 发送事件,通知所有的AutoConfigurationImportListener进行监听
        this.fireAutoConfigurationImportEvents(configurations, exclusions);
        return new AutoConfigurationImportSelector.AutoConfigurationEntry(configurations, exclusions);
    }
} 

接下来再看一下上边源码中调用的
getCandidateConfigurations方法

getCandidateConfigurations

protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {
	// 这里的getSpringFactoriesLoaderFactoryClass()最终返回的是EnableAutoConfiguration.class
    List<String> configurations = SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader());
    Assert.notEmpty(configurations, "No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.");
    return configurations;
} 

从上面的逻辑可以看出,终获取bean的渠道在
SpringFactoriesLoader.loadFactoryNames内SpringFactoriesLoader.loadFactoryNames(this.getSpringFactoriesLoaderFactoryClass(), this.getBeanClassLoader());

SpringFactoriesLoader

loadFactoryNames

public static List<String> loadFactoryNames(Class<?> factoryClass, @Nullable ClassLoader classLoader) {
	// 通过factoryClassName获取相应的bean全称
    String factoryClassName = factoryClass.getName();
    return (List)loadSpringFactories(classLoader).getOrDefault(factoryClassName, Collections.emptyList());
} 

loadSpringFactories

private static Map<String, List<String>> loadSpringFactories(@Nullable ClassLoader classLoader) {
    MultiValueMap<String, String> result = (MultiValueMap)cache.get(classLoader);
    if (result != null) {
        return result;
    } else {
        try {
        	// 获取项目中所有META-INF/spring.factories文件,将其组装成Map
            Enumeration<URL> urls = classLoader != null ? classLoader.getResources("META-INF/spring.factories") : ClassLoader.getSystemResources("META-INF/spring.factories");
            LinkedMultiValueMap result = new LinkedMultiValueMap();

            while(urls.hasMoreElements()) {
                URL url = (URL)urls.nextElement();
                UrlResource resource = new UrlResource(url);
                Properties properties = PropertiesLoaderUtils.loadProperties(resource);
                Iterator var6 = properties.entrySet().iterator();

                while(var6.hasNext()) {
                    Entry<?, ?> entry = (Entry)var6.next();
                    String factoryClassName = ((String)entry.getKey()).trim();
                    String[] var9 = StringUtils.commaDelimitedListToStringArray((String)entry.getValue());
                    int var10 = var9.length;

                    for(int var11 = 0; var11 < var10; ++var11) {
                        String factoryName = var9[var11];
                        result.add(factoryClassName, factoryName.trim());
                    }
                }
            }

            cache.put(classLoader, result);
            return result;
        } catch (IOException var13) {
            throw new IllegalArgumentException("Unable to load factories from location [META-INF/spring.factories]", var13);
        }
    }
} 

每个jar包都可以定义自己的META-INF/spring.factories,在该jar被加载的同时 spring.factories里面定义的 bean就会被自动加载。我们可以来看一下Spring Boot的该配置文件内容【只拿出部分内容】

# Auto Configuration Import Filters
org.springframework.boot.autoconfigure.AutoConfigurationImportFilter=\
org.springframework.boot.autoconfigure.condition.OnBeanCondition,\
org.springframework.boot.autoconfigure.condition.OnClassCondition,\
org.springframework.boot.autoconfigure.condition.OnWebApplicationCondition

# Auto Configure
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\ 

故,我们可以对上边的案例进行改造,在resouces目录下创建该文件,然后添加如下内容

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
top.chenfu.auto.config.MyConfig   

去掉启动类中的@import或者自定义@EnableXXX注解

 

VirtualLab初学者教程-1.用户界面 目录前言一、VirtualLab Fusion简介1.软件2.内置工具箱:二、用户界面认识1.上方菜单栏2.右侧面主窗口3.底部窗口附 前言 感觉做VirtualLab的资料不是特别多,可能用的朋友也比较少吧,笔者最近也因为大创需要刚刚开始入门,把网上有的英文资料整理了一下,加了一点自己的内容发出来希望帮助更多在学习中的朋友,有用词不当之处还请多多包涵。 一、VirtualLab Fusion简介 因为是第一讲,简单啰嗦一下软件本身,参考官方介绍。 1.软件 VirtualLab是由德国LightTran 阅读详情

相关推荐

【人工智能】人工智能基础概念、流派、发展史

人工智能初衷就是让计算机能够像人类一样具有自我思考、自我学习、自我决策的能力。依据百度百科上对人工智能定义:人工智能是研究、开发用于模拟、扩展和延伸人的智能的理论、方法、技术及应用系统的一门新的技术学科。人工智能是研究使计算机来模拟人的某些思维过程和智能行为的学科,主要包括计算机实现智能的原理、制造类似于人脑智能的计算机,使计算机能实现更高层次的应用。

WEL测试 1891

SpringBoot 自动装配流程以及核心源码剖析

Spring Framework 一直在致力于解决一个问题,就是如何让 bean 管理变得更简单,如何让开发者尽可能的少关注一些基础化的 bean 配置,从而实现自动装配。所谓的自动装配,实际上就是如何自动将 bean 装载到 Ioc 容器中来实际上在 spring 3.x 版本中,Enable 模块驱动注解的出现,已经有了一定的自动装配的雏形,而真正能够实现这一机制,还是在 spirng 4.x 版本中,conditional 条件注解的出现;

vnjohn 博主 > 主线分享后端领域业务设计知识、源码思想、架构设计 4008

如何使用Ray和PyTorch训练模型

用户编写训练函数 → 定义单机训练逻辑。通过扩缩容配置 → 指定需要多少资源(Worker 数量、CPU/GPU)。训练器整合训练函数和配置 → 自动将训练函数分发到多个 Worker 上并行执行。Worker 运行训练函数 → 在分布式环境中完成模型训练。通过这种模式,Ray Train 实现了对分布式训练的抽象,用户只需关注单机训练逻辑,无需手动管理分布式通信和资源分配。

m0_62464865的博客 1922

深入分析@Import源码

深入分析@Import源码

及时当勉励,岁月不待人 1033

自动驾驶入门到进阶完整指南:感知、预测、规划、端到端、仿真测评与场景挖掘全解析

对小白来说,不建议一开始直接冲端到端大模型。先学数据和坐标系:否则所有结果都看不懂。再学 LiDAR 3D 检测:最容易建立空间感。再学 BEV/多相机感知:这是当前主流。再学轨迹预测:理解交互和多模态。再学规划控制:理解车为什么这样开。再学仿真和闭环评测:理解 open-loop 和 closed-loop 差异。最后学端到端/VLM/VLA:这时候你才知道它到底替代了哪些模块。贯穿始终学习场景挖掘和安全测评:这是工业界最核心的能力之一。

u013250861的博客 400

SpringBoot实现电子发票生成

电子发票是近年来比较流行的一种票据形式,它取代了以往传统的纸质发票,具有减少纸张浪费、方便有效查验等优点。本文将介绍如何使用Spring Boot和Vue.js构建一个仿真电子发票生成应用程序,借助微信二维码扫描功能和第三方库,实现用户扫描二维码获取发票信息并填写相关开票信息,最后生成电子发票。在本文中,我们介绍了如何使用Spring Boot和Vue.js构建一个仿真电子发票生成应用程序,借助微信二维码扫描功能和第三方库,实现用户扫描二维码获取发票信息并填写相关开票信息,最后生成电子发票。

不愧是暮言的博客 6094

SpringBoot源码分析——【SpringBoot自动装配原理】

3、SpringBoot自动装配 个人理解、仅供参考。 3.1、@SpringBootApplication 先从启动类加上说 @SpringBootApplication public class springBootHelloWorld { public static void main(String[] args) { SpringApplication.run(springBootHelloWorld.class,args); } } @SpringBootAp

weixin_44432069的博客 620

WPS中VBA支持库安装全攻略:从报错到一键解决

VBA作为Office生态中广泛使用的宏语言,是办公自动化的重要基础。WPS表格虽然兼容Excel文件格式,但出于技术路线与授权原因,默认并未集成完整的VBA引擎与开发环境,导致用户打开含宏文件时频繁遇到“找不到工程或库”“未找到VBA支持库”等报错。理解VBA支持库包含引擎与IDE两层结构,并掌握系统位数、版本匹配、安全软件拦截等前置条件,是成功部署的关键。通过可靠的安装源与规范流程完成配置后,即可实现在WPS中运行Excel宏、批量处理数据、自定义函数等自动化场景,显著提升报表处理效率。本文围绕WPS中

weixin_31102231的博客 318

【SpringBoot源码分析】自动装配

SpringBoot源码分析(自动装配):自动装配的原理、相关实现、自定义starter的实现

scj1022的博客 3043

二、声明式 Pipeline 语法

选择型参数,一般用于给定几个可选的值,然后选择其中一个进行赋值,例如:parameters { choice(name: ‘CHOICES’, choices: [‘one’, ‘two’, ‘three’], description: ‘’) },表示定义一个名为 CHOICES 的变量,可选的值为 one、two、three;默认情况下,如果定义了某个 stage 的 agent,在进入该 stage 的 agent 后,该 stage 的 when条件才会被评估,但是可以通过一些选项更改此选项。

Cyan_Jiang的博客 1220

uniapp - 解决苹果ios真机运行报错:错误:请查看是否设备未加入到证书列表或者确认证书类型是否匹配(HbuilderX运行IOS手机出现问题,uniapp运行到IOS真机提示请查看是否设备未)

uni-app,ios苹果,App平台端,uniapp运行到IOS真机提示错误:请查看是否设备未加入到证书列表或者确认证书类型是否匹配,UUID在哪里,uniApp运行到ios真机报错解决,安装自定义基座App失败,没找到有计划资源,证书、标识符和描述文件,证书标识符和描述文件下面没有选项怎么回事,HBuilder真机调试报错请查看是否设备未加入到证书列表或者确认证书类型是否匹配,UniApp运行到IOS真机提示,授权的设备才可以直接安装基座,添加调试的IOS设备,在Devices中,添加手机设备UUID

🏆 前端领域优质创作者 1万+

【JavaEE】Spring Boot 自动装配原理(源码分析)

Spring自动装配原理的源码分析

m0_74105656的博客 1326

【ESP32CAM+Android+OpenCV】自定义目标数据集、训练自己的OpenCV模型部署到手机APP并对ESP32CAM无线图传显示并实时检测识别目标_资料编号30

本项目实现自定义目标数据集(想检测什么就检测什么,按照本文教程自己来更换目标)、训练自己的OpenCV模型实时检测识别(pycharm工程)。手机APP(Android studio工程)部署OpenCV模型实现对ESP32CAM(arduino工程)无线WIFI图传过来的图像实时检测识别。 本文以火焰检测识别为例进行演示,通过该过程,结合本文可自定义尝试更换为其它目标的检测,例如更换为车辆、车牌、手势、人脸面部活动、人脸表情、火焰烟雾、行人、口罩、行为、水果、植物、农作物、建筑、损伤等等部署进行检测。

嵌入式阿齐Archie 3487

mybatis-spring-boot-starter自动装配原理与源码分析

在springboot项目中使用mybatis只需要引入mybatis-spring-boot-starter即可使用,从源码的角度分析其自动装配原理

qq_38318330的博客 3776

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

[Spring boot]源码分析——Spring Boot自动装配原理

[Spring boot]源码分析——Spring Boot自动装配原理 author:陈镇坤27 创建日期:2022年1月25日 文章目录[Spring boot]源码分析——Spring Boot自动装配原理前言Spring Boot的自动配置 ———————————————————————————————— 前言 建议随源码debug一遍。 所选start版本为2.1.6.RELEASE,不同版本的源码执行链不一。 Spring Boot的自动配置 下面是Spring Boot项目的引导类 @Spri

weixin_45528105的博客 272

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

自动装配 自动注入_Spring Boot自动装配原理和源码分析

该篇的主要内容Spring Boot的自动装配原理【有案例模拟】Spring Boot自动装配源码分析SpringBoot中的自动装载原理SpringBoot具备开箱即用的特点,它默默的帮我们做了很多事情【自动创建和装配很多对象】自动装配的实现主要是通过ImportSelector接口完成的自动装配ImportSelectorImportSelector接口是Spring导入外部配置的核心接口,在...

weixin_39944375的博客 240

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Spring Boot 自动装配原理源码分析(五) SpringBoot自动装配源码分析及案例

视频地址:https://www.bilibili.com/video/BV1yr4y1w7ia 代码仓库: https://gitee.com/crazyliyang/video-teaching 我们以 HttpEncodingAutoConfiguration 来进行说明讲解 在 spring-boot-autoconfigure 项目的 META-INF/spring.factories 文件中 # Auto Configure org.springframew...

Crazy_liyang的博客 249

springboot 自动装配_Spring Boot自动装配原理源码分析

1.环境准备使用IDEA Spring Initializr快速创建一个Spring Boot项目添加一个Controller类@RestController public class HelloController { @RequestMapping("hello") public String hello() { return "hello"; } }...

weixin_39671467的博客 106

SpringBoot 自动装配原理源码分析

自动装配实际上就是把第三方组件的Bean装载到IOC容器里,不需要开发人员再去写Bean相关的一个配置

jlihan的博客 1381

Spring Boot 自动装配原理源码分析(一) Spring的@Import注解说明

直接上代码说明: 建立项目 spring-import-selector 核心 MyEnableAutoImportBeans @Retention(RetentionPolicy.RUNTIME) @Documented @Target(ElementType.TYPE) @Import(value = { Dog.class, // 直接 import 一个普通类, 也可以被注册到 IOC 容器中 MyImportSelector.clas...

Crazy_liyang的博客 245

Spring Boot 自动装配原理源码分析(三) Spring Boot 的条件注解

视频地址:https://www.bilibili.com/video/BV1yr4y1w7ia 代码仓库: https://gitee.com/crazyliyang/video-teaching 常用条件注解汇总如下: 注解 处理类 说明 ConditionalOnBean OnBeanCondition 指定的bean都在Spring容器中时才匹配。 ConditionalOnClass OnClassCondition 指定的类都在clas...

Crazy_liyang的博客 311

玩转 Spring Boot 原理篇(内嵌Tomcat实现原理&优雅停机源码剖析)

0.0.0. 历史文章整理玩转 Spring Boot 入门篇玩转 Spring Boot 集成篇(MySQL、Druid、HikariCP)玩转 Spring Boot 集成篇(MyBatis、JPA、事务支持)玩转 Spring Boot 集成篇(Redis)玩转 Spring Boot 集成篇(Actuator、Spring Boot Admin)玩转 Sprin...

一猿小讲 663

Spring Boot 自动装配原理源码分析(四)SpringBoot的@ConfigurationProperties注解

视频地址:https://www.bilibili.com/video/BV1yr4y1w7ia 代码仓库: https://gitee.com/crazyliyang/video-teaching 看项目案例: spring-boot-configuration-properties 本项目比较简单 /** * 配置类 <-> application.yml 节点 { person } */ @Component @ConfigurationPro...

Crazy_liyang的博客 287

Spring Boot 自动装配原理源码分析(二) 手写实现基于Spring的SPI及自动装配

1.关于SPI SPI机制: SPI的全名为( Service Provider Interface ) 这个是针对厂商或者插件的。 (1)SPI思想 系统里抽象的各个模块,往往有很多不同的实现方案,比如日志模块的方案, xml解析模块、jdbc模块的方案等。 向的对象的设计里,我们一般推荐模块之间基于接口编程,模块之间不对实现类进行硬编码。 一旦代码里涉及具体的实现类,就违反了可拔插的原则,如果需要替换一种实现,就需要修改代码。 为了实现在模块装

Crazy_liyang的博客 424

Spring Boot自动配置原理

Spring Boot自动配置原理

2501_94195722的博客 221

SpringBoot3.0.2自动装配实现方式源码分析

启动类通过复合注解@SpringBootApplication中的@SpringBootConfiguration(底层是@Configuration)表示启动类本身也是配置类, 可以在启动类中定义Bean;通过@ComponentScan组件扫描注释, 扫描启动类包及其子包下能被Spring识别的组件;

2503_92489742的博客 1537
上一篇: Spring Bean作用域Scope(含SpringCloud中的RefreshScope )
下一篇: 什么是分布式锁?几种分布式锁分别是怎么实现的?
Java佳佳
博客等级 码龄4年 216粉丝 286原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值