随笔分类 -  spring

摘要:通过spring代码的阅读, 主体流程也就大概出来了. spring里面, 大量使用了后置处理器, 遍布了每个阶段: 实例化前后, 实例化, 属性注入, 初始化 说白了, 就是留了接口, 然后在不同的阶段, 遍历调用不同的接口定义的方法. 来进行一些功能的扩展. 如 aop 也是通过后置处理器, 在 阅读全文
posted @ 2020-07-30 13:48 Sniper_ZL 阅读(319) 评论(0) 推荐(0)
摘要:spring在初始化之后, 还调用了一次 Bean 的后置处理器. 代码片段: org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsAfterIniti 阅读全文
posted @ 2020-07-27 21:32 Sniper_ZL 阅读(1720) 评论(0) 推荐(0)
摘要:代码片段: org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#applyBeanPostProcessorsBeforeInitialization @Override public Object 阅读全文
posted @ 2020-07-27 21:29 Sniper_ZL 阅读(2182) 评论(0) 推荐(0)
摘要:当spring完成属性注入之后, 就要开始 bean 的初始化了 代码片段: org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#doCreateBean // Initialize the bea 阅读全文
posted @ 2020-07-27 21:28 Sniper_ZL 阅读(440) 评论(0) 推荐(0)
摘要:示例 @Component public class IndexA { @Autowired IndexB bbb; public IndexA() { System.out.println("IndexA constructor..."); } public void printf(){ Syst 阅读全文
posted @ 2020-07-27 21:26 Sniper_ZL 阅读(3579) 评论(0) 推荐(1)
摘要:代码片段: org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#populateBean boolean hasInstAwareBpps = hasInstantiationAwareBeanPo 阅读全文
posted @ 2020-07-27 21:25 Sniper_ZL 阅读(2058) 评论(0) 推荐(0)
摘要:代码片段: org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#populateBean if (!mbd.isSynthetic() && hasInstantiationAwareBeanPos 阅读全文
posted @ 2020-07-27 21:24 Sniper_ZL 阅读(1480) 评论(0) 推荐(0)
摘要:属性扫描完成之后, 就可以开始属性注入了. 代码块: org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#doCreateBean boolean earlySingletonExposure = 阅读全文
posted @ 2020-07-27 21:23 Sniper_ZL 阅读(1084) 评论(0) 推荐(0)
摘要:创建完对象之后, 接下来, 就应该想办法对属性进行注入了, 其中就包括 @Autowired 注入 但是在注入之前, 貌似 还没有对 @Autowired 进行扫描和解析. 代码块: if (instanceWrapper == null) { /** * 创建 bean 实例,并将实例包裹在 Be 阅读全文
posted @ 2020-07-27 21:22 Sniper_ZL 阅读(7184) 评论(0) 推荐(2)
摘要:spring在创建对象(org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBeanInstance)的时候, 使用了这个 构造函数后置处理器, 用来选择使用哪个构造函数的. 所以这个后 阅读全文
posted @ 2020-07-27 21:20 Sniper_ZL 阅读(1117) 评论(0) 推荐(0)
摘要:接着前面, 看完构造函数前的后置处理器, 就到 doCreateBean 方法了. protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final @Nullable Object[] 阅读全文
posted @ 2020-07-27 21:18 Sniper_ZL 阅读(934) 评论(0) 推荐(0)
摘要:在 createBean 方法中, doCreateBean 方法前, 调用了这样一句代码: org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory#createBean // Give BeanPos 阅读全文
posted @ 2020-07-27 21:17 Sniper_ZL 阅读(693) 评论(0) 推荐(0)
摘要:由于 getBean 内容比较多, 所以单独出来, 接着上一篇的顺序来看. //org.springframework.beans.factory.support.AbstractBeanFactory#getBean @Override public Object getBean(String n 阅读全文
posted @ 2020-07-27 21:16 Sniper_ZL 阅读(436) 评论(0) 推荐(0)
摘要:执行完前面的步骤后, 回到 org.springframework.context.support.AbstractApplicationContext#refresh 方法. @Override public void refresh() throws BeansException, Illega 阅读全文
posted @ 2020-07-27 21:14 Sniper_ZL 阅读(377) 评论(0) 推荐(0)
摘要:EventListenerMethodProcessor 是 BeanFactory 的一个后置处理器, 用来对 @EventListener 提供支持. 主要是标注了 @EventListener 的方法进行解析, 然后转换为一个 ApplicationListener. 1. 在 refresh 阅读全文
posted @ 2020-07-27 21:10 Sniper_ZL 阅读(1451) 评论(0) 推荐(0)
摘要:demo和 springIOC - ConfigurationClassPostProcessor - full / lite 里面是同一个. 暂且先不管 full , lite 有什么作用, 也不管spring是如何做到的, 如果是自己做, 怎么可以实现那种效果. demo: public cla 阅读全文
posted @ 2020-07-27 21:09 Sniper_ZL 阅读(556) 评论(0) 推荐(0)
摘要:接 springIOC - ConfigurationClassPostProcessor - full / lite 代码块: org.springframework.context.annotation.ConfigurationClassPostProcessor#processConfigB 阅读全文
posted @ 2020-07-27 21:07 Sniper_ZL 阅读(468) 评论(0) 推荐(0)
摘要:开始阅读 Import 源码之前, 也是需要些一些测试demo, 来帮助理解和调试 demo 建几个内容一样的类, 如: IndexDao1, IndexDao2, IndexDao3 其具体内容如下: public class IndexDao1 { public IndexDao1() { Sy 阅读全文
posted @ 2020-07-27 21:06 Sniper_ZL 阅读(394) 评论(0) 推荐(0)
摘要:在接上一篇之前, 我想先写几个测试demo, 应该能帮助更好的理解. demo: com.study.elvinle.ioc.xml.IndexService: public class IndexService { private String name = "index";public Stri 阅读全文
posted @ 2020-07-27 21:05 Sniper_ZL 阅读(367) 评论(0) 推荐(0)
摘要:ConfigurationClassPostProcessor 首先看看他的类的关系: public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPostProcessor, PriorityOrder 阅读全文
posted @ 2020-07-27 20:48 Sniper_ZL 阅读(544) 评论(0) 推荐(0)