前言:学习ChildBeanDefinition
简介 类图
ChildBeanDefinition继承了AbstractBeanDefinition抽象类,bean的相关属性均是在了AbstractBeanDefinition定义,GenericBeanDefinition在继承的基础上重写了一定的方法
ChildBeanDefinition用于定义子Bean信息,和RootBeanDefinition搭配即ChildBeanDefinition对RootBeanDefinition有一定的依赖关系。(功能和GenericBeanDefinition)
源码分析
源码很简单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 public class ChildBeanDefinition extends AbstractBeanDefinition { private String parentName; public ChildBeanDefinition (String parentName) { super (); this .parentName = parentName; } public ChildBeanDefinition (String parentName, MutablePropertyValues pvs) { super (null , pvs); this .parentName = parentName; } public ChildBeanDefinition ( String parentName, ConstructorArgumentValues cargs, MutablePropertyValues pvs) { super (cargs, pvs); this .parentName = parentName; } public ChildBeanDefinition ( String parentName, Class<?> beanClass, ConstructorArgumentValues cargs, MutablePropertyValues pvs) { super (cargs, pvs); this .parentName = parentName; setBeanClass(beanClass); } public ChildBeanDefinition ( String parentName, String beanClassName, ConstructorArgumentValues cargs, MutablePropertyValues pvs) { super (cargs, pvs); this .parentName = parentName; setBeanClassName(beanClassName); } public ChildBeanDefinition (ChildBeanDefinition original) { super (original); } @Override public void setParentName (String parentName) { this .parentName = parentName; } @Override public String getParentName () { return this .parentName; } @Override public void validate () throws BeanDefinitionValidationException { super .validate(); if (this .parentName == null ) { throw new BeanDefinitionValidationException("'parentName' must be set in ChildBeanDefinition" ); } } @Override public AbstractBeanDefinition cloneBeanDefinition () { return new ChildBeanDefinition(this ); } @Override public boolean equals (Object other) { if (this == other) { return true ; } if (!(other instanceof ChildBeanDefinition)) { return false ; } ChildBeanDefinition that = (ChildBeanDefinition) other; return (ObjectUtils.nullSafeEquals(this .parentName, that.parentName) && super .equals(other)); } @Override public int hashCode () { return ObjectUtils.nullSafeHashCode(this .parentName) * 29 + super .hashCode(); } @Override public String toString () { return "Child bean with parent '" + this .parentName + "': " + super .toString(); } }