0%

spring循环依赖二-源码跟踪

流程

第一步:最初的入口

ClassPathXmlApplicationContext:

1
2
3
4
5
6
7
8
9
10
11
public ClassPathXmlApplicationContext(
String[] configLocations, boolean refresh, @Nullable ApplicationContext parent)
throws BeansException {

super(parent);
setConfigLocations(configLocations);
if (refresh) {
//第一步,最初的入口
144 refresh();
}
}

第二步:实例化所有剩余的(非延迟-init)单例

AbstractApplicationContext:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
	@Override
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
//略
try {
//略

// 第二步,实例化所有剩余的(非延迟-init)单例.
517 finishBeanFactoryInitialization(beanFactory);

// 略
}
catch (BeansException ex) {
//略
}
finally {
//略
}
}

第三步

AbstractApplicationContext:

1
2
3
4
5
6
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
//略

//第三步,实例化所有剩余的(非延迟-init)单例.
879 beanFactory.preInstantiateSingletons();
}

第四步:调用子类的doGetBean

DefaultListableBeanFactory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@Override
public void preInstantiateSingletons() throws BeansException {
//略

// 触发所有非惰性单例bean的初始化...
for (String beanName : beanNames) {
RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
if (isFactoryBean(beanName)) {
// 略
}
else {
//第四步,调用子类的doGetBean(name, null, null, false)
897 getBean(beanName);
}
}
}
}

第五(获取Bean的缓存)、七(创建实例)、九步(执行createBean方法)

AbstractBeanFactory

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
protected <T> T doGetBean(
String name, @Nullable Class<T> requiredType, @Nullable Object[] args, boolean typeCheckOnly)
throws BeansException {

String beanName = transformedBeanName(name);
Object bean;

// Eagerly check singleton cache for manually registered singletons.
// 第五步 获取Bean的缓存(其中包括从一级、二级、三级缓存中获取)
250 Object sharedInstance = getSingleton(beanName);
if (sharedInstance != null && args == null) {
if (logger.isTraceEnabled()) {
if (isSingletonCurrentlyInCreation(beanName)) {
logger.trace("Returning eagerly cached instance of singleton bean '" + beanName +
"' that is not fully initialized yet - a consequence of a circular reference");
}
else {
logger.trace("Returning cached instance of singleton bean '" + beanName + "'");
}
}
bean = getObjectForBeanInstance(sharedInstance, name, beanName, null);
}

else {
//略

if (!typeCheckOnly) {
//标记当前bean处于正在创建状态
markBeanAsCreated(beanName);
}

try {
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
checkMergedBeanDefinition(mbd, beanName, args);
//略

// Create bean instance.
if (mbd.isSingleton()) {
// 第七步 创建实例
322 sharedInstance = getSingleton(beanName, () -> {
try {
//第九步,在第八步调用singletonFactory.getObject()执行此lambda方法
324 return createBean(beanName, mbd, args);
}
catch (BeansException ex) {
// Explicitly remove instance from singleton cache: It might have been put there
// eagerly by the creation process, to allow for circular reference resolution.
// Also remove any beans that received a temporary reference to the bean.
destroySingleton(beanName);
throw ex;
}
});
bean = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);
}

else if (mbd.isPrototype()) {
// It's a prototype -> create a new instance.
Object prototypeInstance = null;
try {
beforePrototypeCreation(beanName);
prototypeInstance = createBean(beanName, mbd, args);
}
finally {
afterPrototypeCreation(beanName);
}
bean = getObjectForBeanInstance(prototypeInstance, name, beanName, mbd);
}

else {
String scopeName = mbd.getScope();
if (!StringUtils.hasLength(scopeName)) {
throw new IllegalStateException("No scope name defined for bean ´" + beanName + "'");
}
Scope scope = this.scopes.get(scopeName);
if (scope == null) {
throw new IllegalStateException("No Scope registered for scope name '" + scopeName + "'");
}
try {
Object scopedInstance = scope.get(beanName, () -> {
beforePrototypeCreation(beanName);
try {
return createBean(beanName, mbd, args);
}
finally {
afterPrototypeCreation(beanName);
}
});
bean = getObjectForBeanInstance(scopedInstance, name, beanName, mbd);
}
catch (IllegalStateException ex) {
throw new BeanCreationException(beanName,
"Scope '" + scopeName + "' is not active for the current thread; consider " +
"defining a scoped proxy for this bean if you intend to refer to it from a singleton",
ex);
}
}
}
catch (BeansException ex) {
cleanupAfterBeanCreationFailure(beanName);
throw ex;
}
}

// Check if required type matches the type of the actual bean instance.
if (requiredType != null && !requiredType.isInstance(bean)) {
try {
T convertedBean = getTypeConverter().convertIfNecessary(bean, requiredType);
if (convertedBean == null) {
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
}
return convertedBean;
}
catch (TypeMismatchException ex) {
if (logger.isTraceEnabled()) {
logger.trace("Failed to convert bean '" + name + "' to required type '" +
ClassUtils.getQualifiedName(requiredType) + "'", ex);
}
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
}
}
return (T) bean;
}

第六(获取不到Bean的缓存)、十八步(获取到Bean的三级缓存生成对象放入二级缓存)

DefaultSingletonBeanRegistry:

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
//第六步,获取Bean的缓存(其中包括从一级、二级、三级缓存中获取)
protected Object getSingleton(String beanName, boolean allowEarlyReference) {
// Quick check for existing instance without full singleton lock
//1.先从一级缓存中获取对象,若存在则返回
182 Object singletonObject = this.singletonObjects.get(beanName);
if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {
//2.若对象不存在,则从二级缓存中查找该对象
singletonObject = this.earlySingletonObjects.get(beanName);
if (singletonObject == null && allowEarlyReference) {
synchronized (this.singletonObjects) {
// Consistent creation of early reference within full singleton lock
singletonObject = this.singletonObjects.get(beanName);
//3.若对象不存在一级、二级缓存中时,并且存在于三级缓存中时
if (singletonObject == null) {
singletonObject = this.earlySingletonObjects.get(beanName);
if (singletonObject == null) {
ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);
if (singletonFactory != null) {
//4.调用工厂对象的getObject()方法【() -> getEarlyBeanReference(beanName, mbd, bean)】
// 提前,实际上是调用了【AnnotationAwareAspectJAutoProxyCreator】
// 第十八步,最终返回一个动态代理对象Proxy
194 singletonObject = singletonFactory.getObject();
//将该动态代理对象存放到二级缓存中
this.earlySingletonObjects.put(beanName, singletonObject);
//把该bean的函数接口从三级缓存中移除
this.singletonFactories.remove(beanName);
}
}
}
}
}
}
return singletonObject;
}

第八(执行第七步传入的lambda表达式)、二十一步(添加到一级缓存中,然后调用链将回到初始化实例的函数)

DefaultSingletonBeanRegistry:

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
public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
Assert.notNull(beanName, "Bean name must not be null");
synchronized (this.singletonObjects) {
//1.从缓存中获取bean实例
Object singletonObject = this.singletonObjects.get(beanName);
//2.如果bean实例不存在缓存中
if (singletonObject == null) {
/* 省略部分源码 */
try {
//第八步,调用第七步传入的lambda表达式() -> { return createBean(beanName, mbd, args);}
234 singletonObject = singletonFactory.getObject();
newSingleton = true;
}
catch (IllegalStateException ex) {
/* 省略部分源码 */
}

if (newSingleton) {
//第二十步,添加到一级缓存中,然后调用链将回到初始化实例的函数
260 addSingleton(beanName, singletonObject);
}
}
return singletonObject;
}
}

第十步:创建一个bean实

AbstractAutowireCapableBeanFactory:

1
2
3
4
5
6
7
8
9
10
11
12
13
@Override
protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)
// 略
try {
//第十步,创建一个bean实例,填充bean实例、应用前置处理器等
516 Object beanInstance = doCreateBean(beanName, mbdToUse, args);
if (logger.isTraceEnabled()) {
logger.trace("Finished creating instance of bean '" + beanName + "'");
}
return beanInstance;
}
//略
}

第十一(实例化对象,开辟内存空间)、十二步(添加Bean的工厂对象到三级缓存中)、十九步(获取到二级缓存中提前暴露的A)

AbstractAutowireCapableBeanFactory:

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
protected Object doCreateBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)
throws BeanCreationException {

// Instantiate the bean.
BeanWrapper instanceWrapper = null;
if (mbd.isSingleton()) {
//第十一步,实例化对象,开辟内存空间
556 instanceWrapper = this.factoryBeanInstanceCache.remove(beanName);
}

//略

//快速缓存单例,以便能够解决循环引用
// Eagerly cache singletons to be able to resolve circular references
// even when triggered by lifecycle interfaces like BeanFactoryAware.
// 实例化完成后,判断是否需要提前暴露该对象,结果为true
// 满足条件:单例、开启允许循环依赖的配置、并且该Bean处于正在创建状态
boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&
isSingletonCurrentlyInCreation(beanName));
if (earlySingletonExposure) {
if (logger.isTraceEnabled()) {
logger.trace("Eagerly caching bean '" + beanName +
"' to allow for resolving potential circular references");
}
//第十二步,添加Bean的工厂对象到三级缓存中
587 addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean));
}

// Initialize the bean instance.
Object exposedObject = bean;
try {
//第十三步,填充属性,即给A的属性赋值(也就是属性B)
593 populateBean(beanName, mbd, instanceWrapper);
exposedObject = initializeBean(beanName, exposedObject, mbd);
}
catch (Throwable ex) {
//略
}

if (earlySingletonExposure) {
//第十九步,获取到二级缓存中提前暴露的A
607 Object earlySingletonReference = getSingleton(beanName, false);
if (earlySingletonReference != null) {
if (exposedObject == bean) {
exposedObject = earlySingletonReference;
}
else if (!this.allowRawInjectionDespiteWrapping && hasDependentBean(beanName)) {
String[] dependentBeans = getDependentBeans(beanName);
Set<String> actualDependentBeans = new LinkedHashSet<>(dependentBeans.length);
for (String dependentBean : dependentBeans) {
if (!removeSingletonIfCreatedForTypeCheckOnly(dependentBean)) {
actualDependentBeans.add(dependentBean);
}
}
if (!actualDependentBeans.isEmpty()) {
throw new BeanCurrentlyInCreationException(beanName,
"Bean with name '" + beanName + "' has been injected into other beans [" +
StringUtils.collectionToCommaDelimitedString(actualDependentBeans) +
"] in its raw version as part of a circular reference, but has eventually been " +
"wrapped. This means that said other beans do not use the final version of the " +
"bean. This is often the result of over-eager type matching - consider using " +
"'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.");
}
}
}
}

// Register bean as disposable.
try {
registerDisposableBeanIfNecessary(beanName, bean, mbd);
}
catch (BeanDefinitionValidationException ex) {
throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex);
}

return exposedObject;
}

第十三步:给给Bean的属性赋值

AbstractAutowireCapableBeanFactory

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
protected void populateBean(String beanName, RootBeanDefinition mbd, @Nullable BeanWrapper bw) {
if (bw == null) {
if (mbd.hasPropertyValues()) {
throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Cannot apply property values to null instance");
}
else {
// Skip property population phase for null instance.
return;
}
}

// Give any InstantiationAwareBeanPostProcessors the opportunity to modify the
// state of the bean before properties are set. This can be used, for example,
// to support styles of field injection.
//当像BeanFactoryAware这样的生命周期接口触发时,任何实例化的awarebeanpostprocessor都有机会在属性设置之前修改bean的状态
if (!mbd.isSynthetic() && hasInstantiationAwareBeanPostProcessors()) {
for (BeanPostProcessor bp : getBeanPostProcessors()) {
if (bp instanceof InstantiationAwareBeanPostProcessor) {
InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;
if (!ibp.postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)) {
return;
}
}
}
}

PropertyValues pvs = (mbd.hasPropertyValues() ? mbd.getPropertyValues() : null);

int resolvedAutowireMode = mbd.getResolvedAutowireMode();
if (resolvedAutowireMode == AUTOWIRE_BY_NAME || resolvedAutowireMode == AUTOWIRE_BY_TYPE) {
MutablePropertyValues newPvs = new MutablePropertyValues(pvs);
// Add property values based on autowire by name if applicable.
if (resolvedAutowireMode == AUTOWIRE_BY_NAME) {
autowireByName(beanName, mbd, bw, newPvs);
}
// Add property values based on autowire by type if applicable.
if (resolvedAutowireMode == AUTOWIRE_BY_TYPE) {
autowireByType(beanName, mbd, bw, newPvs);
}
pvs = newPvs;
}

boolean hasInstAwareBpps = hasInstantiationAwareBeanPostProcessors();
boolean needsDepCheck = (mbd.getDependencyCheck() != AbstractBeanDefinition.DEPENDENCY_CHECK_NONE);

PropertyDescriptor[] filteredPds = null;
if (hasInstAwareBpps) {
if (pvs == null) {
pvs = mbd.getPropertyValues();
}
for (BeanPostProcessor bp : getBeanPostProcessors()) {
if (bp instanceof InstantiationAwareBeanPostProcessor) {
InstantiationAwareBeanPostProcessor ibp = (InstantiationAwareBeanPostProcessor) bp;
PropertyValues pvsToUse = ibp.postProcessProperties(pvs, bw.getWrappedInstance(), beanName);
if (pvsToUse == null) {
if (filteredPds == null) {
filteredPds = filterPropertyDescriptorsForDependencyCheck(bw, mbd.allowCaching);
}
pvsToUse = ibp.postProcessPropertyValues(pvs, filteredPds, bw.getWrappedInstance(), beanName);
if (pvsToUse == null) {
return;
}
}
pvs = pvsToUse;
}
}
}
if (needsDepCheck) {
if (filteredPds == null) {
filteredPds = filterPropertyDescriptorsForDependencyCheck(bw, mbd.allowCaching);
}
checkDependencies(beanName, mbd, filteredPds, pvs);
}

if (pvs != null) {
//第十三步,给Bean的属性赋值
1442 applyPropertyValues(beanName, mbd, bw, pvs);
}
}

第十四(属性解析器获取property的实际内容)、二十一步(真正的属性赋值)

AbstractAutowireCapableBeanFactory

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
	protected void applyPropertyValues(String beanName, BeanDefinition mbd, BeanWrapper bw, PropertyValues pvs) {
if (pvs.isEmpty()) {
return;
}

if (System.getSecurityManager() != null && bw instanceof BeanWrapperImpl) {
((BeanWrapperImpl) bw).setSecurityContext(getAccessControlContext());
}

MutablePropertyValues mpvs = null;
List<PropertyValue> original;

if (pvs instanceof MutablePropertyValues) {
mpvs = (MutablePropertyValues) pvs;
if (mpvs.isConverted()) {
// Shortcut: use the pre-converted values as-is.
try {
bw.setPropertyValues(mpvs);
return;
}
catch (BeansException ex) {
throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Error setting property values", ex);
}
}
original = mpvs.getPropertyValueList();
}
else {
original = Arrays.asList(pvs.getPropertyValues());
}

TypeConverter converter = getCustomTypeConverter();
if (converter == null) {
converter = bw;
}
BeanDefinitionValueResolver valueResolver = new BeanDefinitionValueResolver(this, beanName, mbd, converter);

// Create a deep copy, resolving any references for values.
List<PropertyValue> deepCopy = new ArrayList<>(original.size());
boolean resolveNecessary = false;
for (PropertyValue pv : original) {
if (pv.isConverted()) {
deepCopy.add(pv);
}
else {
//获取属性名称
String propertyName = pv.getName();
Object originalValue = pv.getValue();
if (originalValue == AutowiredPropertyMarker.INSTANCE) {
Method writeMethod = bw.getPropertyDescriptor(propertyName).getWriteMethod();
if (writeMethod == null) {
throw new IllegalArgumentException("Autowire marker for property without write method: " + pv);
}
originalValue = new DependencyDescriptor(new MethodParameter(writeMethod, 0), true);
}
//第十四步 使用解析器解析不同类型的值
1697 Object resolvedValue = valueResolver.resolveValueIfNecessary(pv, originalValue);
Object convertedValue = resolvedValue;
boolean convertible = bw.isWritableProperty(propertyName) &&
!PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName);
if (convertible) {
convertedValue = convertForProperty(resolvedValue, propertyName, bw, converter);
}
//略
}
}
//略
// Set our (possibly massaged) deep copy.
try {
//第二十步,真正的属性赋值
1730 bw.setPropertyValues(new MutablePropertyValues(deepCopy));
}
catch (BeansException ex) {
throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Error setting property values", ex);
}
}

第十五步:

BeanDefinitionValueResolver

1
2
3
4
5
6
7
8
9
10
	public Object resolveValueIfNecessary(Object argName, @Nullable Object value) {
// We must check each value to see whether it requires a runtime reference
// to another bean to be resolved.
if (value instanceof RuntimeBeanReference) {
RuntimeBeanReference ref = (RuntimeBeanReference) value;
//第十五步
113 return resolveReference(argName, ref);
}
//略
}

第十六步:调用子类的doGetBean

BeanDefinitionValueResolver

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
	private Object resolveReference(Object argName, RuntimeBeanReference ref) {
try {
Object bean;
Class<?> beanType = ref.getBeanType();
if (ref.isToParent()) {
//略
}
else {
String resolvedName;
if (beanType != null) {
NamedBeanHolder<?> namedBean = this.beanFactory.resolveNamedBean(beanType);
bean = namedBean.getBeanInstance();
resolvedName = namedBean.getBeanName();
}
else {
resolvedName = String.valueOf(doEvaluate(ref.getBeanName()));
//第十六步,调用子类的doGetBean(name, null, null, false)
330 bean = this.beanFactory.getBean(resolvedName);
}
this.beanFactory.registerDependentBean(resolvedName, this.beanName);
}
if (bean instanceof NullBean) {
bean = null;
}
return bean;
}
catch (BeansException ex) {
//略
}
}

第十七步:循环第五步创建B

AbstractBeanFactory

归纳步骤:

实例化A

1.第五步getSingleton(beanName)从缓存获取A

2.获取不到时,走第七步准备开始创建;

3.第十一步,实例化对象,开辟内存空间

4.到第十二步addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean))将A的ObjectFactory放入三级缓存中;

获取A的属性B

5.第十三步populateBean(beanName, mbd, instanceWrapper),给A的赋值属性B

6.走第五步获取B,返现B没有,继续重复流程创建B

实例化B

7.走第七步准备开始创建B;

8.第十一步,实例化对象,开辟内存空间

9.到第十二步addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean))将B的ObjectFactory放入三级缓存中;

获取B的属性A

10.再次来到第十三步B的赋值属性A时;

11.第十六步,调用子类的doGetBean(name, null, null, false)

11.再次走第五步获取A

12.十八步获取到A的三级缓存生成对象放入二级缓存,如果有aop最终返回一个动态代理对象Proxy,移除三级缓存A的工厂;

13.第二十步 真正的属性赋值,将A赋值给B

14.第二十一步B放入addSingleton一级缓存,删除二级、三级缓存中的数据

15.回到第十三步populateBean(beanName, mbd, instanceWrapper),给A的赋值属性B时,走类似10之后的流程;

16.最终A放入addSingleton一级缓存,删除二级、三级缓存中的数据

主要方法

getSingleton:获取各级缓存

doCreateBean:创建bean主要方法

populateBean:填充属性方法

addSingleton:添加一级缓存方法

简单总结

结合上面四个方法做个简单的总结:

1
2
3
4
5
6
7
8
9
10
1.调用doGetBean()方法,想要获取A,于是调用getSingleton()方法,从缓存中查找A
2.在getSingleton()方法中,从一级缓存中查找,没有,返回null
3.doGet】Bean()方法中获取的A为null,于是走对应的处理逻辑,调用getSingleton()的重载方法(参数为ObjectFactory)
4.在getSingleton()方法中,现将A的name添加到一个集合中,用于标记该bean正常创建中;然后回调匿名内部类的createBean方法
5.进入AbstractAutowireCapableBeanFactory#doCreateBean,先反射调用构造器创建出A的实例,然后判断是否为单例、是否允许提前曝光引用(单例一般为true)、是否正在创建中(第四步的集合);判断为true则将A添加到三级缓存中
6.对A进行属性填充,此时检测到A依赖于B,于是开始查找B
7.调用doGetBean()方法和上面A的过程一样,到缓存中查找B,没有则创建,然后给B填充属性
8.此时B依赖于A,调用getSingle()获取A,依次从缓存中茶渣,此时从三级缓存中获取到A的工厂,通过公办工厂获取singletonObject,此时这个singleton指向就是上面在doCreate()方法中实例化的A(第七步)
9.这样B就获取到了A的依赖,于是B顺利完成实例化,并将A从三级缓存移动到二级缓存中
10.随后A继续它的属性填充工作,此时也获取到B,A也随之完成创建,回到getSingleton()方法中继续向下执行,将A从二级缓存移动到一级缓存中