摘要: 1.0 自定义标签的解析. 在之前的章节中,我们完成了对spring 默认标签的加载过程.那么现在我们将开始新的里程, spring 自定义标签的解析;代码如下: 1 /** 2 * Parse the elements at the root level in the docu... 阅读全文
posted @ 2014-04-07 21:28 mjorcen 阅读(1365) 评论(0) 推荐(0)
摘要: 对于嵌入式的beans标签,想信大家很少使用过,或者接触过,起码,我本人就没用过. 它非常类似于Import标签所提供的功能;使用如下: 对这个beans没什么太多可讲,解析代码如下: 1 protected void doRegisterBeanDefinitions(Element root) { 2 String profileSpec = root.getAttribute(PROFILE_ATTRIBUTE); 3 // 处理profile属性 4 /* 5 * this is header... 6 ... 阅读全文
posted @ 2014-04-07 00:12 mjorcen 阅读(554) 评论(0) 推荐(0)
摘要: 对于spring配置文件的编写,我想,对于经历过庞大项目的人,都有那种恐惧的心理,太多的配置文件。不过,分模块都是大多数人能想到的方法,但是,怎么分模块,那就是仁者见仁,智者见智了。我的策略是使用import。基本代码格式如下web.xml applicationContext.xml文件中使用import的方式导入有模块配置文件,以后若有新模块的加入,那就可以简单修改这个文件了,这样大大的简化了配置文件后期的复杂程度; Spring 的解析代码如下; 1 /** 2 * Parse an "import" element an... 阅读全文
posted @ 2014-04-07 00:06 mjorcen 阅读(645) 评论(0) 推荐(0)
摘要: 对于之前漫长的,最核心的Bean标签的解析就没什么好讲的了,首先看看使用方法: 解析过程如下: 1 /** 2 * Process the given alias element, registering the alias with the registry. 3 */ 4 protected void processAliasRegistration(Element ele) { 5 // 获取beanName 6 String name = ele.getAttribute(NA... 阅读全文
posted @ 2014-04-06 23:47 mjorcen 阅读(3168) 评论(0) 推荐(0)
摘要: 1.0registerBeanDefinition 对于配置文件,解析也解析完了,装饰也装饰完了,对于得到的BeanDefinition已经可以满足后续的使用了,唯一剩下的工作就是注册了,也就是: processBeanDefinition 方法中的BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder,getReaderContext().getRegistry()); 代码如下: 1 /** 2 * Process the given bean element, parsing the bean definiti... 阅读全文
posted @ 2014-04-06 23:23 mjorcen 阅读(655) 评论(0) 推荐(0)
摘要: 到这里,我们已经完成了分析默认标签的解析与提取过程,或许设计的内容太多,我们忘了我们是冲哪个函数开始了的,让我们再次回顾一下默认标签解析方法的起始方法.入口如下: 1 /** 2 * Parse the elements at the root level in the document: "import", "alias", "bean". 3 * 4 * @param root the DOM root element of the document 5 */ 6 protected void parseBeanDefinitio 阅读全文
posted @ 2014-04-06 16:54 mjorcen 阅读(569) 评论(0) 推荐(0)
摘要: 之前,我们已尽完成了xml 文档到 GenericBeanDefinition的转换,也就是说,到这里,所有的配置都可以在GenericBeanDefinition 的实例中找到对应的配置. GenericBeanDefinition只是子类实现,而大部分功能都是通用属性,都是保存在AbstractBeanDefinition中,那么我们再次通过AbstractBeanDefinition 的属性来复习一下 我们都解析了哪些对应的配置.AbstractBeanDefinition 的结果图如下:我们在来看看源代码! 1 /** 2 * Base class for concrete... 阅读全文
posted @ 2014-04-06 14:26 mjorcen 阅读(1060) 评论(0) 推荐(0)
摘要: 对于qualifier 子元素,我们接触的更多的是注解形式,在使用Spring 自动注入时,Spring 容器中匹配的候选 Bean 数目必须有且仅有一个。当找不到一个匹配的 Bean 时,Spring 容器将抛出BeanCreationException 异常,并指出必须至少拥有一个匹配的 Bean。Spring 允许我们通过 @Qualifier 注释指定注入 Bean 的名称,这样歧义就消除了,可以通过下面的方法解决异常。首先我们先看看他的用法.注解形式是这样的:@Qualifier("XXX") 中的 XX是 Bean 的名称,所以 @Autowired 和 @Qu 阅读全文
posted @ 2014-04-06 01:30 mjorcen 阅读(2591) 评论(0) 推荐(0)
摘要: 1.0 Property子元素的使用 property 子元素是再常用不过的了, 在看Spring源码之前,我们先看看它的使用方法,1. 实例类如下: 1 public class Animal { 2 3 public String type; 4 5 public Set age; 6 7 private Map sell; 8 9 public Animal() {10 11 }12 13 /**14 * @return the type15 */16 public String getType() {... 阅读全文
posted @ 2014-04-06 01:03 mjorcen 阅读(783) 评论(0) 推荐(0)
摘要: 对于构造函数子元素是非常常用的. 相信大家也一定不陌生,举个小例子: 1 public class Animal { 2 3 public String type; 4 5 public int age; 6 7 /** 8 * @param type 9 * @param age10 */11 public Animal(String type, int age) {12 super();13 this.type = type;14 this.age = age;15 ... 阅读全文
posted @ 2014-04-05 17:29 mjorcen 阅读(1902) 评论(0) 推荐(0)