
spring
文章平均质量分 83
not back
这个作者很懒,什么都没留下…
展开
-
SpringBoot源码(十四):spring三级缓存源码,解决循环依赖
介绍在写springboot项目时,我们对于bean的注入都使用注解的方式进行注入。可以根据field注入,set方法注入还有构造器方法注入。但是我们都写过类似下面的代码:@Servicepublic class Bean1 { @Autowired private Bean2 bean2;}@Servicepublic class Bean2 { @Autowired private Bean1 bean1;}即Bean1和Bean2互相引用,原创 2021-04-28 10:32:42 · 2721 阅读 · 0 评论 -
SpringBoot源码(十三):spring获取bean的源码
介绍前面一章说了AbstractApplicationContext中的refresh方法中的invokeBeanFactoryPostProcessors。主要是调用BeanFactoryPostProcessor。其中也有获取bean的过程,就是beanFactory.getBean的方法。这一章就说下getBean这个方法。由于spring中获取bean的方法比较复杂,涉及到的流程也非常多,这一章就先说下整个大体的流程。其中的细节会在后面也会慢慢说。源码直接看源码吧 @Overrid原创 2021-04-23 21:36:37 · 1338 阅读 · 5 评论 -
SpringBoot源码(十二):refreshContext(二) invokeBeanFactoryPostProcessors
介绍接着说refreshContext中的内容,invokeBeanFactoryPostProcessors方法。这个方法主要就是调用实现spring的BeanFactoryPostProcessor的实现类。源码先来介绍下BeanFactoryPostProcessor接口。public interface BeanFactoryPostProcessor { void postProcessBeanFactory(ConfigurableListableBeanFactory b原创 2021-04-21 21:49:56 · 424 阅读 · 1 评论 -
SpringBoot源码(十一): refreshContext(一)
介绍refreshContext是springBoot启动源码中最复杂的部分了,里面的内容也非常多,将会拆分很多个章节去说。源码refreshContext里面就是调用AbstractApplicationContext的refresh的方法。主要的功能就是注册spring容器里面的bean,以及对bean的处理还有广播等功能。接着看源码吧 public void refresh() throws BeansException, IllegalStateException { sy原创 2021-04-13 23:33:31 · 813 阅读 · 1 评论 -
SpringBoot源码(十): prepareContext
介绍前面一章介绍了创建ApplicationContext,这章将会介绍ApplicationContext的一些处理工作。源码 private void prepareContext(ConfigurableApplicationContext context, ConfigurableEnvironment environment, SpringApplicationRunListeners listeners, ApplicationArguments application原创 2021-03-25 22:05:23 · 361 阅读 · 1 评论 -
SpringBoot源码(九): createApplicationContext
介绍前面一章介绍了启动流程中的打印banner,接下来继续根据springBoot启动的源码分析,createApplicationContext方法。ApplicationContext是spring容器的核心,其实一般我们所说的spring容器,一般也可以说是ApplicationContext,具体点就是ApplicationContext里的DefaultListableBeanFactory,后面在bean的创建时候会详细介绍的,现在就先了解下ApplicationContext的创建,以及在原创 2021-03-24 23:43:58 · 741 阅读 · 1 评论 -
SpringBoot源码(八): 打印banner
介绍接着prepareEnvironment之后继续介绍springBoot启动流程的代码,接下来看看banner的打印。源码 private Banner printBanner(ConfigurableEnvironment environment) { // banner模式,如果为off则不打印 if (this.bannerMode == Banner.Mode.OFF) { return null; } ResourceLoader reso.原创 2021-03-22 16:27:04 · 1084 阅读 · 0 评论 -
SpringBoot源码(七): ConfigFileApplicationListener
介绍configFileApplicationListener是spring中对于配置文件解析的监听器,主要是负责对于配置文件的解析,并且加入到environment中去。源码在上一章中prepareEnvironment方法,会发送广播ApplicationEnvironmentPreparedEvent事件到广播,然后各个监听器接收处理。对于如何设别到监听器就不多解释了,之前也介绍过。别的监听器暂时先不看,先看最重要的configFileApplicationListener。直接看C.原创 2021-03-21 13:00:28 · 2588 阅读 · 0 评论 -
SpringBoot源码(六): 启动流程:prepareEnvironment
介绍前面介绍了spring对于键值的抽象PropertySource,以及对外提供数据的统一处理接口PropertyResolver。还有对ConfigurableEnvironment的源码解析。接下来继续看springBoot启动流程的源码prepareEnvironment。prepareEnvironment private ConfigurableEnvironment prepareEnvironment( SpringApplicationRunListeners l.原创 2021-03-11 21:51:57 · 966 阅读 · 0 评论 -
SpringBoot源码(五): ConfigurableEnvironment
介绍Environment是spring中配置文件数据的载体,对外暴露使用的配置文件名称,如:profiles.active,这样我们就可以知道在使用哪个配置文件的信息了。ConfigurableEnvironment继承于Environment,并且ConfigurableEnvironment还继承了ConfigurablePropertyResolver,而ConfigurablePropertyResolver继承于PropertyResolver。对于PropertyResolver上原创 2021-03-11 15:45:51 · 10263 阅读 · 2 评论 -
SpringBoot源码(四): PropertySource以及解析
介绍ConfigurableEnvironment是spring容器中非常重要的角色,它继承Environment,主要负责解析profile的定义,以及解析文件放到map中供spring容器去使用。源码public interface ConfigurableEnvironment extends Environment, ConfigurablePropertyResolver { void setActiveProfiles(String... profiles); vo原创 2021-03-10 21:26:30 · 2679 阅读 · 0 评论 -
SpringBoot源码(三): ApplicationArguments
介绍继续之前说的从springboot启动去阅读源码在 listeners.starting()之后就到了参数解析了,再次发一下启动的源码; public ConfigurableApplicationContext run(String... args) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); ConfigurableApplicationContext context = null; Co.原创 2021-02-24 20:55:57 · 1007 阅读 · 0 评论 -
SpringBoot源码(二): SpringApplicationRunListeners.starting()
介绍上一章介绍了springBoot启动时候,还未运行run方法时的初始化。现在继续介绍run方法的内容。下面就是run方法的所有内容了,接下来会分步去介绍各个类和方法的作用。public ConfigurableApplicationContext run(String... args) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); ConfigurableApplicationContext contex原创 2021-02-02 23:32:45 · 1597 阅读 · 0 评论 -
SpringBoot源码(一): 启动SpringBoot时的初始化
SpringBoot源码(一)最近自己看了一点springBoot的源码,想要整理一下。供自己学习,顺便看看能不能对有疑惑的小伙伴有帮助。介绍版本:2.0建议新看源码的小伙伴还是先看1.5版本的,和2.x版本的差异不是很大。主要是2.x版本用到了太多的lambda的匿名类特性,以至于逻辑不太容易理解。这里我是先看了1.5的版本,然后又去看了下2.x版本的。这边主要是从springBoot的启动开始分析源码,通过分析整个启动流程,来看看springBoot和spring的源码。..原创 2021-02-01 21:47:10 · 1267 阅读 · 2 评论