- 博客(9)
- 资源 (15)
- 收藏
- 关注
原创 Spring Boot源码 - @ConditionalOnBean实现分析
在上一篇@Conditional之后,知道了动态判断注册bean的是怎么实现的。执行的时机,回调时传入了什么对象,只是在Spring BootCondition下面会有很多更复杂的情况,所以就使用比较常见的@ConditionalOnBean为例,分析其结构和回调的逻辑。@Target({ ElementType.TYPE, ElementType.METHOD })@Retention(RetentionPolicy.RUNTIME)@Documented@Conditional...
2020-06-30 22:29:12 1500
原创 Spring源码 - @Conditional实现分析
@Conditional是Spring 4出现的注解,但是真正露出价值的是Spring Boot的扩展@ConditionalOnBean等。但是任然使用的是Spring框架进行处理,并没有做太多定制的东西,所以还是先看看@Conditional注解的实现。@Target({ElementType.TYPE, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Con...
2020-06-28 23:46:21 693
原创 Spring Boot源码(六) - 自动装配(下)- AutoConfigurationImportSelector
继续上一篇,知道了执行时机和调用顺序,继续分析两个方法的逻辑,是怎样实现自动装配的。AutoConfigurationImportSelector.AutoConfigurationGroup1、process@Overridepublic void process(AnnotationMetadata annotationMetadata, DeferredImportSelector deferredImportSelector) { // 断言判断,肯定为true ...
2020-06-26 14:38:51 2548
原创 Spring源码 - DeferredImportSelector实现分析
在分析DeferredImportSelector之前,根据名字Deferred(延迟的)ImportSelector。ImportSelector则是将selectImports返回的字符串数组,注册成为Bean,详细过程可以参见:Spring源码-ImportSelector实现分析。那么有几个问题:1)、怎么延迟的;2)、执行时机,或者在什莫时候被调用的;3)、返回后的字符串数组,怎么注册成Bean(或者Beandefinition)。 之前在分析Spring源码时,并没有分析D...
2020-06-26 09:57:41 3463 1
原创 Spring Boot源码(五) - 自动装配(上)
按照SpringApplication的run方法执行流程,在refreshContext时候会调用refresh方法,其中会在ConfigurationClassPostProcessor中处理@Import,ImportSelector等(详细可以参见:SpringIoc源码(十)- ApplicationContext(六)- refresh(ConfigurationClassPostProcessor上)或Spring源码-ImportSelector实现分析)。而自动装配则是通过@...
2020-06-24 20:33:13 682
原创 Spring Boot源码(四) - prepareEnvironment、反射创建ApplicationContext对象、prepareContext
目录一、Environment初始化二、反射创建ApplicationContext对象// 将main方法的args参数进行封装ApplicationArguments applicationArguments = new DefaultApplicationArguments(args);// 准备EnvironmentConfigurableEnvironment environment = prepareEnvironment(listeners, applicationArgu
2020-06-22 22:10:11 752
原创 Spring Boot源码(三) - SpringApplicationRunListener(EventPublishingRunListener)生命周期和回调时机
Spring Boot定义的SpringApplicationRunListener实现类只有EventPublishingRunListener,主要是定义了其生命周期,并且在Spring Boot启动过程中完成回调。
2020-06-20 21:37:14 2161
原创 Spring Boot源码(二) - SpringApplication的run方法
Spring Boot在执行SpringApplication的run方法之前,其实在构造函数中已经完成了很多初始化的准备操作,并且在run方法之前我们可以配置很多信息(上一篇博客中分析了很多的字段都是有Setter的)。比如我们可以将代码写作如下:
2020-06-20 13:04:31 1248
原创 Spring Boot源码(一) - 分析总览
Spring Boot当前版本为2.2.0,之前一直对Spring Boot的各个模块比较模糊,很难理解自动装配等注解与容器启动的关系等。还是先看一下,Spring Boot的特点:1、2、3、4、5、6、
2020-06-18 22:45:54 382
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人