Avoid decorated definition bypass for scoped proxy determination
GenericApplicationContext registers proxy hints without any SmartInstantiationAwareBeanPostProcessor involved as well. Closes gh-29335
This commit is contained in:
parent
5dca43ebd6
commit
6b6cf1b4a2
|
@ -689,7 +689,22 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||||
}
|
}
|
||||||
|
|
||||||
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
|
RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);
|
||||||
|
Class<?> beanClass = predictBeanType(beanName, mbd);
|
||||||
|
|
||||||
|
if (beanClass != null) {
|
||||||
|
// Check bean class whether we're dealing with a FactoryBean.
|
||||||
|
if (FactoryBean.class.isAssignableFrom(beanClass)) {
|
||||||
|
if (!BeanFactoryUtils.isFactoryDereference(name)) {
|
||||||
|
// If it's a FactoryBean, we want to look at what it creates, not at the factory class.
|
||||||
|
beanClass = getTypeForFactoryBean(beanName, mbd, allowFactoryBeanInit).resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (BeanFactoryUtils.isFactoryDereference(name)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (beanClass == null) {
|
||||||
// Check decorated bean definition, if any: We assume it'll be easier
|
// Check decorated bean definition, if any: We assume it'll be easier
|
||||||
// to determine the decorated bean's type than the proxy's type.
|
// to determine the decorated bean's type than the proxy's type.
|
||||||
BeanDefinitionHolder dbd = mbd.getDecoratedDefinition();
|
BeanDefinitionHolder dbd = mbd.getDecoratedDefinition();
|
||||||
|
@ -700,23 +715,10 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||||
return targetClass;
|
return targetClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<?> beanClass = predictBeanType(beanName, mbd);
|
|
||||||
|
|
||||||
// Check bean class whether we're dealing with a FactoryBean.
|
|
||||||
if (beanClass != null && FactoryBean.class.isAssignableFrom(beanClass)) {
|
|
||||||
if (!BeanFactoryUtils.isFactoryDereference(name)) {
|
|
||||||
// If it's a FactoryBean, we want to look at what it creates, not at the factory class.
|
|
||||||
return getTypeForFactoryBean(beanName, mbd, allowFactoryBeanInit).resolve();
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return beanClass;
|
return beanClass;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
return (!BeanFactoryUtils.isFactoryDereference(name) ? beanClass : null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getAliases(String name) {
|
public String[] getAliases(String name) {
|
||||||
|
|
|
@ -439,11 +439,23 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||||
List<SmartInstantiationAwareBeanPostProcessor> bpps =
|
List<SmartInstantiationAwareBeanPostProcessor> bpps =
|
||||||
PostProcessorRegistrationDelegate.loadBeanPostProcessors(
|
PostProcessorRegistrationDelegate.loadBeanPostProcessors(
|
||||||
this.beanFactory, SmartInstantiationAwareBeanPostProcessor.class);
|
this.beanFactory, SmartInstantiationAwareBeanPostProcessor.class);
|
||||||
|
|
||||||
for (String beanName : this.beanFactory.getBeanDefinitionNames()) {
|
for (String beanName : this.beanFactory.getBeanDefinitionNames()) {
|
||||||
Class<?> beanType = this.beanFactory.getType(beanName);
|
Class<?> beanType = this.beanFactory.getType(beanName);
|
||||||
if (beanType != null) {
|
if (beanType != null) {
|
||||||
|
registerProxyHintIfNecessary(beanType, runtimeHints);
|
||||||
for (SmartInstantiationAwareBeanPostProcessor bpp : bpps) {
|
for (SmartInstantiationAwareBeanPostProcessor bpp : bpps) {
|
||||||
beanType = bpp.determineBeanType(beanType, beanName);
|
Class<?> newBeanType = bpp.determineBeanType(beanType, beanName);
|
||||||
|
if (newBeanType != beanType) {
|
||||||
|
registerProxyHintIfNecessary(newBeanType, runtimeHints);
|
||||||
|
beanType = newBeanType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerProxyHintIfNecessary(Class<?> beanType, RuntimeHints runtimeHints) {
|
||||||
if (Proxy.isProxyClass(beanType)) {
|
if (Proxy.isProxyClass(beanType)) {
|
||||||
// A JDK proxy class needs an explicit hint
|
// A JDK proxy class needs an explicit hint
|
||||||
runtimeHints.proxies().registerJdkProxy(beanType.getInterfaces());
|
runtimeHints.proxies().registerJdkProxy(beanType.getInterfaces());
|
||||||
|
@ -458,9 +470,6 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue