我们知道Spring支持SPEL语言,支持注册编辑等扩展性的功能。这些扩展性的功能在Spring中是如何处理的。这就是我们即将要了解的函数prepareBeanFactory。一样的,我们先来看时序图。

(相关资源可到这里下载:http://pan.baidu.com/s/1sjSo9a9)

通过上面的时序图,我们可能很清楚得知道,扩展功能就是AdbstractApplicationContext中执行的,所以我们找到这个函数,并对其作分析。

protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) {// Tell the internal bean factory to use the context's class loader etc.//设置beanFactory的classLoader为当前context的classLoaderbeanFactory.setBeanClassLoader(getClassLoader());//设置beanFactory的表达式语言处理,Spring3增加了表达式语言的支持//默认可以使用#{bean.xxx}的形式来调用相关属性值beanFactory.setBeanExpressionResolver(new StandardBeanExpressionResolver(beanFactory.getBeanClassLoader()));//为beanFactory增加了默认的propertyEditor,这个主要是对bean的属性等设置管理一个工具beanFactory.addPropertyEditorRegistrar(new ResourceEditorRegistrar(this, getEnvironment()));// Configure the bean factory with context callbacks.//添加BeanPostProcessorbeanFactory.addBeanPostProcessor(new ApplicationContextAwareProcessor(this));//设置了几个忽略自动装配的接口beanFactory.ignoreDependencyInterface(ResourceLoaderAware.class);beanFactory.ignoreDependencyInterface(ApplicationEventPublisherAware.class);beanFactory.ignoreDependencyInterface(MessageSourceAware.class);beanFactory.ignoreDependencyInterface(ApplicationContextAware.class);beanFactory.ignoreDependencyInterface(EnvironmentAware.class);// BeanFactory interface not registered as resolvable type in a plain factory.// MessageSource registered (and found for autowiring) as a bean.//设置了几个自动装配的特殊规则beanFactory.registerResolvableDependency(BeanFactory.class, beanFactory);beanFactory.registerResolvableDependency(ResourceLoader.class, this);beanFactory.registerResolvableDependency(ApplicationEventPublisher.class, this);beanFactory.registerResolvableDependency(ApplicationContext.class, this);// Detect a LoadTimeWeaver and prepare for weaving, if found.//增加对AspectJ的支持if (beanFactory.containsBean(LOAD_TIME_WEAVER_BEAN_NAME)) {beanFactory.addBeanPostProcessor(new LoadTimeWeaverAwareProcessor(beanFactory));// Set a temporary ClassLoader for type matching.beanFactory.setTempClassLoader(new ContextTypeMatchClassLoader(beanFactory.getBeanClassLoader()));}// Register default environment beans.//添加默认的系统环境beanif (!beanFactory.containsLocalBean(ENVIRONMENT_BEAN_NAME)) {beanFactory.registerSingleton(ENVIRONMENT_BEAN_NAME, getEnvironment());}if (!beanFactory.containsLocalBean(SYSTEM_PROPERTIES_BEAN_NAME)) {beanFactory.registerSingleton(SYSTEM_PROPERTIES_BEAN_NAME, getEnvironment().getSystemProperties());}if (!beanFactory.containsLocalBean(SYSTEM_ENVIRONMENT_BEAN_NAME)) {beanFactory.registerSingleton(SYSTEM_ENVIRONMENT_BEAN_NAME, getEnvironment().getSystemEnvironment());}}

上面的函数中主要进行了几个方面的扩展:

1)        增加对SPEL语言的支持

2)        增加对属性编辑的支持

3)        增加了一些内置类,比如EnvironmentAware、MessageSouceAware的信息注入

4)        设置了依赖功能可忽略的接口

5)        注册一些固定依赖的属性

6)        增加AspectJ的支持

7)        将相关环境变量及属性注册以单例模式注册

Spring源码之ApplicationContext(四)功能补充相关推荐

  1. spring源码分析第四天------springmvc核心原理及源码分析

    spring源码分析第四天------springmvc核心原理及源码分析 1.基础知识普及 2. SpringMVC请求流程 3.SpringMVC代码流程 4.springMVC源码分析 4.1 ...

  2. 第五篇:Spring源码篇-ApplicationContext

    Spring源码篇-ApplicationContext   前面通过手写IoC,DI.AOP和Bean的配置.到最后ApplicationContext的门面处理,对于Spring相关的核心概念应该 ...

  3. Spring源码之ApplicationContext

    ​ 本文是针对Srping的ClassPathXMLApplicationContext来进行源码解析,在本篇博客中将不会讲述spring Xml解析注册代码,因为ApplicationContext ...

  4. Spring源码学习(四) | @Configuration的cglib动态代理

    文章目录 前言 例子 @Configuration :full or lite 设置 full or lite Cglib生成代理类AppConfig Where is it generated Ho ...

  5. Spring源码解析-applicationContext.xml加载和bean的注册

    applicationContext文件加载和bean注册流程 ​ Spring对于从事Java开发的boy来说,再熟悉不过了,对于我们这个牛逼的框架的介绍就不在这里复述了,Spring这个大杂烩,怎 ...

  6. Spring源码学习第四天==>初识Refresh()

    Spring中AbstractApplicationContext的Refresh方法 Refresh方法可以算的上是SpringIOC容器启动的核心方法了.这几天进行了深入的学习,溯源,整理流程图. ...

  7. spring源码解析(四) 推断构造方法

    该篇以createBeanInstance方法为起点分析推断构造方法 怎么一步步到createBeanInstance方法 refresh()->finishBeanFactoryInitial ...

  8. Spring 源码解析(四):bean的加载

    //spring.xml 文件解析BeanFactory factory = new XmlBeanFactory(new ClassPathResource("spring.xml&quo ...

  9. 【06】Spring源码-分析篇-ApplicationContext

    Spring源码篇-ApplicationContext   前面通过手写IoC,DI.AOP和Bean的配置.到最后ApplicationContext的门面处理,对于Spring相关的核心概念应该 ...

  10. spring 源码_spring源码系列(一)——spring循环引用

    众所周知spring在默认单例的情况下是支持循环引用的 为了节省图片大小我把那些可以动得gif图片做成了只循环一次,如果看到图片不动了请右键选择在新标签打开,那么图片就会动,手机用户则更简单,直接手指 ...

最新文章

  1. CMD用什么命令可以删除服务?
  2. 为什么很多程序员面试造火箭,入职拧螺丝?
  3. JAVA学习笔记04
  4. dosbox中的bebug指令
  5. 新建VHDL的Vivado工程
  6. 网易新闻 时事新闻抓取链接
  7. linux 文件名带特殊符号,Linux删除含有特殊符号文件名的文件
  8. 从join on和where执行顺序认识T-SQL查询处理执行顺序
  9. 蓝桥杯 ADV-187 算法提高 勾股数
  10. The log scan number (620023:3702:1) passed to log scan in database 'xxxx' is not valid
  11. 产品经理三大文档--BRD、MRD、PRD解读
  12. cdlinux教程wpa2无线网络密码破解
  13. c语言作业朱鸣华,C语言程序设计习题解析与上机指导 第3版
  14. 浅谈智能卡技术在数字电视小额支付系统中的应用
  15. 什么是股票量化交易软件?
  16. HDU1880——哈希表(BKDR算法)——魔咒词典
  17. 达叔机器学习笔记1_逻辑回归建立一般流程
  18. C# 通用分页用户控件
  19. C#通过ToLower()方法将字符串转换成小写的代码
  20. 运维学习之lvm(逻辑卷管理)

热门文章

  1. Software--Data Visual 数据可视化
  2. 字符串数组排序,如果可以保证前一个字符的末尾与后一个字符的开头相同,返回1,否则返回-1...
  3. 游戏开发之多态及虚函数(C++基础)
  4. 验证码识别——基于CNN+BLSTM+CTC秒杀不定长复杂验证码
  5. 1.1.6版本Druid连接MSSQLServer 2008 R2报错The query timeout value -1 is not valid. #2210
  6. OPPO以技术推动产品 获专利数首次挺近前十
  7. 【对讲机的那点事】安装中继台天馈系统如何制作同轴电缆BNC接头?
  8. 团队作业——四则运算网页版
  9. Eclipse下PHP开发 插件安装
  10. oracle列表分区ADD VALUES或DROP VALUES包含数据变化