Introspect pre-registered singletons in preDetermineBeanTypes as well
Closes gh-33668
This commit is contained in:
@@ -425,25 +425,37 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
|
||||
* @see SmartInstantiationAwareBeanPostProcessor#determineBeanType
|
||||
*/
|
||||
private void preDetermineBeanTypes(RuntimeHints runtimeHints) {
|
||||
List<String> singletons = new ArrayList<>();
|
||||
List<String> lazyBeans = new ArrayList<>();
|
||||
|
||||
// First round: pre-registered singleton instances, if any.
|
||||
for (String beanName : this.beanFactory.getSingletonNames()) {
|
||||
Class<?> beanType = this.beanFactory.getType(beanName);
|
||||
if (beanType != null) {
|
||||
ClassHintUtils.registerProxyIfNecessary(beanType, runtimeHints);
|
||||
}
|
||||
singletons.add(beanName);
|
||||
}
|
||||
|
||||
List<SmartInstantiationAwareBeanPostProcessor> bpps =
|
||||
PostProcessorRegistrationDelegate.loadBeanPostProcessors(
|
||||
this.beanFactory, SmartInstantiationAwareBeanPostProcessor.class);
|
||||
|
||||
List<String> lazyBeans = new ArrayList<>();
|
||||
|
||||
// First round: non-lazy singleton beans in definition order,
|
||||
// Second round: non-lazy singleton beans in definition order,
|
||||
// matching preInstantiateSingletons.
|
||||
for (String beanName : this.beanFactory.getBeanDefinitionNames()) {
|
||||
BeanDefinition bd = getBeanDefinition(beanName);
|
||||
if (bd.isSingleton() && !bd.isLazyInit()) {
|
||||
preDetermineBeanType(beanName, bpps, runtimeHints);
|
||||
}
|
||||
else {
|
||||
lazyBeans.add(beanName);
|
||||
if (!singletons.contains(beanName)) {
|
||||
BeanDefinition bd = getBeanDefinition(beanName);
|
||||
if (bd.isSingleton() && !bd.isLazyInit()) {
|
||||
preDetermineBeanType(beanName, bpps, runtimeHints);
|
||||
}
|
||||
else {
|
||||
lazyBeans.add(beanName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Second round: lazy singleton beans and scoped beans.
|
||||
// Third round: lazy singleton beans and scoped beans.
|
||||
for (String beanName : lazyBeans) {
|
||||
preDetermineBeanType(beanName, bpps, runtimeHints);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user