还是以之前的代码为准吧,下面贴测试方法。
@Configuration
@ComponentScan(basePackages = "com.gee")
public class Config {
public static void main(String args[]) {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class);
}
}
实例化的代码是在容器进行刷新的时候所进行的。在spring如何通过注解配置来注册bean的笔记里已经有讲过一部分内容,所以的话,部分内容选择跳过。
public AnnotationConfigApplicationContext(Class<?>... annotatedClasses) {
//父类的构造方法则会先创建beanFac,此外也会将容器自身包装成资源加载器并且注入
//这里会生成AnnoatedBeanDefinitionReader,同时与容器关联,通过容器取得资源加载器以及beanFac最后将内部类注册到BeanFac中
this();
//注册配置类 就是Config
register(annotatedClasses);
//容器刷新。。。直接往里面走吧。最后还是去到AbstractApplicationContext的刷新方法。
refresh();
}
}
public abstract class AbstractApplicationContext extends DefaultResourceLoader
implements ConfigurableApplicationContext {
@Override
public void refresh() throws BeansException, IllegalStateException {
synchronized (this.startupShutdownMonitor) {
// Prepare this context for refreshing.
//刷新前的前置准备,更改容器的激活还有关闭状态,另外初始化需要加载的文本。
prepareRefresh();
// Tell the subclass to refresh the internal bean factory.
//从容器获取beanFactory,这里并没有注册到任何东西,与xml方式不一样
ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();
// Prepare the bean factory for use in this context.
//bean工厂使用之前的准备工作
prepareBeanFactory(beanFactory);
try {
// Allows post-processing of the bean factory in context subclasses.
//bean工厂的后置处理,由子类去实现。这里并没有任何子类去实现
postProcessBeanFactory(beanFactory);
// Invoke factory processors registered as beans in the context.
//bean工厂的后置处理,此处是重点。BeanFac的后置处理器的执行。。。只关心这个方法即可
invokeBeanFactoryPostProcessors(beanFactory);
// Register bean processors that intercept bean creation.
//注册bean的后置处理器,finishBeanFactoryInitialization中实例化bean之后会调用该后置处理器。
registerBeanPostProcessors(beanFactory);
// Initialize message source for this context.
initMessageSource();
// Initialize event multicaster for this context.
//初始化容器的EventMulticaster,可以处理事件以及监听器的对应关系
initApplicationEventMulticaster();
// Initialize other special beans in specific context subclasses.
//提供给子类去实现的一个方法
onRefresh();
// Check for listener beans and register them.
//注册监听器
registerListeners();
// Instantiate all remaining (non-lazy-init) singletons.
//完成bean工厂的初始化---bean如何去实例化的。这一个方法是主要内容,因此其他方法掠过,暂时不看那么细。直接往这个方法里面走。
finishBeanFactoryInitialization(beanFactory);
// Last step: publish corresponding event.
//完成刷新
finishRefresh();
}
catch (BeansException ex) {
if (logger.isWarnEnabled()) {
logger.warn("Exception encountered during context initialization - " +
"cancelling refresh attempt: " + ex);
}
// Destroy already created singletons to avoid dangling resources.
destroyBeans();
// Reset 'active' flag.
cancelRefresh(ex);
// Propagate exception to caller.
throw ex;
}
finally {
// Reset common introspection caches in Spring's core, since we
// might not ever need metadata for singleton beans anymore...
resetCommonCaches();
}
}
}
/**
* Finish the initialization of this context's bean factory,
* initializing all remaining singleton beans.
*/
看看上方的注释,初始化所有剩余没有初始化的单例,完成容器的beanFactory的初始化
protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
// 初始化容器的转化服务类
if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) &&
beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) {
beanFactory.setConversionService(
beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
}
// Register a default embedded value resolver if no bean post-processor
// (such as a PropertyPlaceholderConfigurer bean) registered any before:
// at this point, primarily for resolution in annotation attribute values.
if (!beanFactory.hasEmbeddedValueResolver()) {
beanFactory.addEmbeddedValueResolver(strVal -> getEnvironment().resolvePlaceholders(strVal));
}
// Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
for (String weaverAwareName : weaverAwareNames) {
getBean(weaverAwareName);
}
// Stop using the temporary ClassLoader for type matching.
beanFactory.setTempClassLoader(null);
// Allow for caching all bean definition metadata, not expecting further changes.
beanFactory.freezeConfiguration();
// 初始化所有剩余的非懒加载单例。直接往这个方法里面走。直接看下面DefalutListableBeanFacotry的代码
beanFactory.preInstantiateSingletons();
}
}
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory
implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable {
//该方法是ConfigurableListableBeanFactory的接口
@Override
public void preInstantiateSingletons() throws BeansException {
if (this.logger.isDebugEnabled()) {
this.logger.debug("Pre-instantiating singletons in " + this);
}
//获取注册表。就是注册的bean的名字集合
List<String> beanNames = new ArrayList<>(this.beanDefinitionNames);
// 遍历bean名称集合,去实现初始化。
for (String beanName : beanNames) {
RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
//如果不是抽象的,且是单例,且不是懒加载,就进行创建。
if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
//先判断是不是factoryBean类型的子类,FactoryBean是一个工厂Bean,提供了接口可以直接返回实例对象,factoryBean是spring提供的一个接口,提供了类对象的返回以及是否单例的状态判断功能以及类对象的返回。这里演示一下factoryBean的用法。[https://www.jianshu.com/writer#/notebooks/44580062/notes/71842542]
//如果是factoryBean,这里是通过判断2步,首先是判断是否可以从单例缓存中获取,如果获取到实例,则判断类型,否则,会去注册表中是否可以找到对应的BeanDefition,判断是否为FactoryBean的子类。这里其实发现无论怎么都会走getBean方法,那么直接往里面走就好了
if (isFactoryBean(beanName)) {
//FactoryBean会加个前缀 &前缀
final FactoryBean<?> factory = (FactoryBean<?>) getBean(FACTORY_BEAN_PREFIX + beanName);
boolean isEagerInit;
if (System.getSecurityManager() != null && factory instanceof SmartFactoryBean) {
isEagerInit = AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
((SmartFactoryBean<?>) factory).isEagerInit(),
getAccessControlContext());
}
else {
isEagerInit = (factory instanceof SmartFactoryBean &&
((SmartFactoryBean<?>) factory).isEagerInit());
}
if (isEagerInit) {
getBean(beanName);
}
}
else {
//那么直接看看getBean方法好了,以config为例子,最终是走到这里,直接往里面走
getBean(beanName);
}
}
}
// Trigger post-initialization callback for all applicable beans...
for (String beanName : beanNames) {
Object singletonInstance = getSingleton(beanName);
if (singletonInstance instanceof SmartInitializingSingleton) {
final SmartInitializingSingleton smartSingleton = (SmartInitializingSingleton) singletonInstance;
if (System.getSecurityManager() != null) {
AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
smartSingleton.afterSingletonsInstantiated();
return null;
}, getAccessControlContext());
}
else {
smartSingleton.afterSingletonsInstantiated();
}
}
}
}
}
public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport implements ConfigurableBeanFactory {
@Override
public Object getBean(String name) throws BeansException {
//继续往里面走
return doGetBean(name, null, null, false);
}
//整个方法有点长只看注释部分即可
protected <T> T doGetBean(final String name, @Nullable final Class<T> requiredType,
@Nullable final Object[] args, boolean typeCheckOnly) throws BeansException {
//处理名字,若有&则去除即可,这是对FactoryBean的特殊处理
final String beanName = transformedBeanName(name);
Object bean;
// 这里面的话,就是从缓存中获取,spring有三级缓存,三个级别中只会有一个级别是有对应的数据的,用于解决依赖注入,这里后面会讲。优先级分别就是从上往下寻找
// 第一级是DefaultSingletonBeanRegistry.singletonObjects,这里存放的是完善的实例
// 第二级是DefaultSingletonBeanRegistry.earlySingletonObjects,这里存放的是不完善的实例,如依赖注入未完成的实例
// 第三级是DefaultSingletonBeanRegistry.singletonFactories,这里存放的是ObjectFactory,提供一个getObject方法返回实例
Object sharedInstance = getSingleton(beanName);
if (sharedInstance != null && args == null) {
if (logger.isDebugEnabled()) {
if (isSingletonCurrentlyInCreation(beanName)) {
logger.debug("Returning eagerly cached instance of singleton bean '" + beanName +
"' that is not fully initialized yet - a consequence of a circular reference");
}
else {
logger.debug("Returning cached instance of singleton bean '" + beanName + "'");
}
}
//若缓存不为空,就直接获取bean,这里一开始的话,肯定是不会走到的,所以先略过,
bean = getObjectForBeanInstance(sharedInstance, name, beanName, null);
}
else {
//多状的bean是不允许循环依赖的,那么如何判断是否循环依赖呢,这里边有一个ThreadLoacl变量,用于存储正在创建的bean,若已经存在这个beanName,那必然是循环依赖了。这里也说明,多态是不允许循环依赖的
if (isPrototypeCurrentlyInCreation(beanName)) {
throw new BeanCurrentlyInCreationException(beanName);
}
// 从父工厂中去获取查找还有获取bean实例
BeanFactory parentBeanFactory = getParentBeanFactory();
if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
// Not found -> check parent.
String nameToLookup = originalBeanName(name);
if (parentBeanFactory instanceof AbstractBeanFactory) {
return ((AbstractBeanFactory) parentBeanFactory).doGetBean(
nameToLookup, requiredType, args, typeCheckOnly);
}
else if (args != null) {
// Delegation to parent with explicit args.
return (T) parentBeanFactory.getBean(nameToLookup, args);
}
else {
// No args -> delegate to standard getBean method.
return parentBeanFactory.getBean(nameToLookup, requiredType);
}
}
//这里一直为true
if (!typeCheckOnly) {
//标记这个bean正在创建中,重新融合beanDefinition这里没看懂
markBeanAsCreated(beanName);
}
try {
//获取整合的beanDefinition
final RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
checkMergedBeanDefinition(mbd, beanName, args);
// 强依赖 也是不能解决循环依赖的,明显会栈溢出,spring为了避免这个,所以记载了bean之间的依赖关系,用于判断是否循环依赖。因为使用了递归getBean(dep)
String[] dependsOn = mbd.getDependsOn();
if (dependsOn != null) {
for (String dep : dependsOn) {
//此处就是判断循环依赖的方法,[https://www.jianshu.com/writer#/notebooks/44580062/notes/71875318]
if (isDependent(beanName, dep)) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
"Circular depends-on relationship between '" + beanName + "' and '" + dep + "'");
}
//存放依赖与被依赖的关系集合,如哪个类被哪些类依赖,哪个类依赖于哪些类
registerDependentBean(dep, beanName);
//获取并且创建bean实例,若显示循环依赖必然报错
getBean(dep);
}
}
//如果bean为单例的话,那就会直接通过该方法来获取实例。那么下面先直接讲解一下getSingleton方法,随后再讲解一下createBean方法。直接进入getSingleton内部。
if (mbd.isSingleton()) {
sharedInstance = getSingleton(beanName, () -> {
try {
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);
}
//bean如果为多态
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);
}
//由于prototypeInstance不一定是最终的bean实例,需要判断一下,再最终返回
bean = getObjectForBeanInstance(prototypeInstance, name, beanName, mbd);
}
else {
//这里就是bean的其他域,如request, session,暂时不讲
String scopeName = mbd.getScope();
final 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.isDebugEnabled()) {
logger.debug("Failed to convert bean '" + name + "' to required type '" +
ClassUtils.getQualifiedName(requiredType) + "'", ex);
}
throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
}
}
return (T) bean;
}
}
下面直接看看getSingleton方法
public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements SingletonBeanRegistry {
public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {
Assert.notNull(beanName, "Bean name must not be null");
//先加锁
synchronized (this.singletonObjects) {
//从一级缓存中获取实例
Object singletonObject = this.singletonObjects.get(beanName);
//若不存在,且正在摧毁中,则会直接抛异常
if (singletonObject == null) {
if (this.singletonsCurrentlyInDestruction) {
throw new BeanCreationNotAllowedException(beanName,
"Singleton bean creation not allowed while singletons of this factory are in destruction " +
"(Do not request a bean from a BeanFactory in a destroy method implementation!)");
}
if (logger.isDebugEnabled()) {
logger.debug("Creating shared instance of singleton bean '" + beanName + "'");
}
beforeSingletonCreation(beanName);
boolean newSingleton = false;
boolean recordSuppressedExceptions = (this.suppressedExceptions == null);
if (recordSuppressedExceptions) {
this.suppressedExceptions = new LinkedHashSet<>();
}
try {
//从singletonFactory中获取对象
singletonObject = singletonFactory.getObject();
//设置标记,表示为新创建的单例
newSingleton = true;
}
catch (IllegalStateException ex) {
// Has the singleton object implicitly appeared in the meantime ->
// if yes, proceed with it since the exception indicates that state.
singletonObject = this.singletonObjects.get(beanName);
if (singletonObject == null) {
throw ex;
}
}
catch (BeanCreationException ex) {
if (recordSuppressedExceptions) {
for (Exception suppressedException : this.suppressedExceptions) {
ex.addRelatedCause(suppressedException);
}
}
throw ex;
}
finally {
if (recordSuppressedExceptions) {
this.suppressedExceptions = null;
}
afterSingletonCreation(beanName);
}
//新创建的同时,还需要将实例添加到一级缓存中去,直接看看addSingleton方法
if (newSingleton) {
addSingleton(beanName, singletonObject);
}
}
return singletonObject;
}
}
很明显了 这个方法就是将实例添加到一级缓存同时清除其他缓存,顺便添加到实例的注册表中去,
protected void addSingleton(String beanName, Object singletonObject) {
synchronized (this.singletonObjects) {
this.singletonObjects.put(beanName, singletonObject);
this.singletonFactories.remove(beanName);
this.earlySingletonObjects.remove(beanName);
this.registeredSingletons.add(beanName);
}
}
}
那么剩下对就是ObjectFacotry是怎么生成的
ObjectFacotry是一个接口,函数式接口
@FunctionalInterface
public interface ObjectFactory<T> {
/**
* Return an instance (possibly shared or independent)
* of the object managed by this factory.
* @return the resulting instance
* @throws BeansException in case of creation errors
*/
T getObject() throws BeansException;
}
看看createBean方法是怎么生成ObjectFactory的
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory
implements AutowireCapableBeanFactory {
*/
@Override
protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)
throws BeanCreationException {
if (logger.isDebugEnabled()) {
logger.debug("Creating instance of bean '" + beanName + "'");
}
RootBeanDefinition mbdToUse = mbd;
// Make sure bean class is actually resolved at this point, and
// clone the bean definition in case of a dynamically resolved Class
// which cannot be stored in the shared merged bean definition.
Class<?> resolvedClass = resolveBeanClass(mbd, beanName);
if (resolvedClass != null && !mbd.hasBeanClass() && mbd.getBeanClassName() != null) {
mbdToUse = new RootBeanDefinition(mbd);
mbdToUse.setBeanClass(resolvedClass);
}
// Prepare method overrides.
try {
mbdToUse.prepareMethodOverrides();
}
catch (BeanDefinitionValidationException ex) {
throw new BeanDefinitionStoreException(mbdToUse.getResourceDescription(),
beanName, "Validation of method overrides failed", ex);
}
try {
// Give BeanPostProcessors a chance to return a proxy instead of the target bean instance.
//这里就是给用户提供一个机会通过后置处理器去返回代理对象,这里面其实也是找到后置处理器的实现类,然后执行获取返回值,这里因为本身没有去实现对应接口,所以当然没有值
Object bean = resolveBeforeInstantiation(beanName, mbdToUse);
if (bean != null) {
return bean;
}
}
catch (Throwable ex) {
throw new BeanCreationException(mbdToUse.getResourceDescription(), beanName,
"BeanPostProcessor before instantiation of bean failed", ex);
}
try {
//创建bean,直接进入该方法
Object beanInstance = doCreateBean(beanName, mbdToUse, args);
if (logger.isDebugEnabled()) {
logger.debug("Finished creating instance of bean '" + beanName + "'");
}
return beanInstance;
}
catch (BeanCreationException ex) {
// A previously detected exception with proper bean creation context already...
throw ex;
}
catch (ImplicitlyAppearedSingletonException ex) {
// An IllegalStateException to be communicated up to DefaultSingletonBeanRegistry...
throw ex;
}
catch (Throwable ex) {
throw new BeanCreationException(
mbdToUse.getResourceDescription(), beanName, "Unexpected exception during bean creation", ex);
}
}
protected Object doCreateBean(final String beanName, final RootBeanDefinition mbd, final @Nullable Object[] args)
throws BeanCreationException {
BeanWrapper instanceWrapper = null;
//判断是否为单例
if (mbd.isSingleton()) {
//若为单例,首先看看缓存中是否存在对应的FactoryBean
instanceWrapper = this.factoryBeanInstanceCache.remove(beanName);
}
//若缓存不存在,则直接创建
if (instanceWrapper == null) {
//创建beanInstance,方法很复杂,其实最后就是通过mbd的class进行反射,获取实例
instanceWrapper = createBeanInstance(beanName, mbd, args);
}
final Object bean = instanceWrapper.getWrappedInstance();
Class<?> beanType = instanceWrapper.getWrappedClass();
if (beanType != NullBean.class) {
mbd.resolvedTargetType = beanType;
}
// Allow post-processors to modify the merged bean definition.
synchronized (mbd.postProcessingLock) {
if (!mbd.postProcessed) {
try {
applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);
}
catch (Throwable ex) {
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
"Post-processing of merged bean definition failed", ex);
}
mbd.postProcessed = true;
}
}
// 为了解决循环依赖,所以允许缓存提前被使用
boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&
isSingletonCurrentlyInCreation(beanName));
if (earlySingletonExposure) {
if (logger.isDebugEnabled()) {
logger.debug("Eagerly caching bean '" + beanName +
"' to allow for resolving potential circular references");
}
//将创建后的bean加入第三级缓存中
addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean));
}
// Initialize the bean instance.
Object exposedObject = bean;
try {
//解决循环依赖,后面再讲
populateBean(beanName, mbd, instanceWrapper);
exposedObject = initializeBean(beanName, exposedObject, mbd);
}
catch (Throwable ex) {
if (ex instanceof BeanCreationException && beanName.equals(((BeanCreationException) ex).getBeanName())) {
throw (BeanCreationException) ex;
}
else {
throw new BeanCreationException(
mbd.getResourceDescription(), beanName, "Initialization of bean failed", ex);
}
}
if (earlySingletonExposure) {
//再次从缓存中获取实例,以一级二级缓存的例子为准,因为传了false,所以不会读取第三级缓存
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 " +
"'getBeanNamesOfType' 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;
}
}
到这里其实怎么实例化的过程已经完成了。
下面先简单做一下总结。
1.当AnnotationConfigApplicationContext的构造方法开始执行的时候会优先进行父类构造方法的执行
2.父类构造方法的执行,涉及到2个重要的点,会创建beanFactory以及资源加载器,以及将一些内部处理器优先注册到beanFactory中
3.注册配置类
4.开始刷新,更新容器的状态,初始化需要加载的文本
5.获取beanFactory
6.获取beanFactory的后置处理器,对beanFactory进行后置处理
7.注册bean的后置处理器
8.初始化消息源
9.初始化容器事件的修改器
10.进行刷新
11.注册监听器
12.进行bean实例的初始化
12.1首先试图DefaultSingletonBeanRegistry中获取缓存,缓存必然一开始是空的
12.2强依赖的实现
12.3创建bean实例,获取bean的后置处理器,对bean进行处理
12.4将创建后的FactoryBean放入第三级缓存中
12.5解决bean实例的循环依赖
12.6返回FactoryBean
12.7通过FactoryBean获取实例对象,并且放入一级缓存中
13.完成刷新