|
|
|
@ -1,5 +1,5 @@ |
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -552,7 +552,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp |
|
|
|
|
|
|
|
|
|
// Check bean class whether we're dealing with a FactoryBean.
|
|
|
|
|
if (FactoryBean.class.isAssignableFrom(beanType)) { |
|
|
|
|
if (!BeanFactoryUtils.isFactoryDereference(name)) { |
|
|
|
|
if (!BeanFactoryUtils.isFactoryDereference(name) && beanInstance == null) { |
|
|
|
|
// If it's a FactoryBean, we want to look at what it creates, not the factory class.
|
|
|
|
|
beanType = getTypeForFactoryBean(beanName, mbd); |
|
|
|
|
if (beanType == null) { |
|
|
|
@ -1614,8 +1614,13 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp |
|
|
|
|
Object beanInstance, String name, String beanName, @Nullable RootBeanDefinition mbd) { |
|
|
|
|
|
|
|
|
|
// Don't let calling code try to dereference the factory if the bean isn't a factory.
|
|
|
|
|
if (BeanFactoryUtils.isFactoryDereference(name) && !(beanInstance instanceof FactoryBean)) { |
|
|
|
|
throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass()); |
|
|
|
|
if (BeanFactoryUtils.isFactoryDereference(name)) { |
|
|
|
|
if (beanInstance instanceof NullBean) { |
|
|
|
|
return beanInstance; |
|
|
|
|
} |
|
|
|
|
if (!(beanInstance instanceof FactoryBean)) { |
|
|
|
|
throw new BeanIsNotAFactoryException(transformedBeanName(name), beanInstance.getClass()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Now we have the bean instance, which may be a normal bean or a FactoryBean.
|
|
|
|
|