Introspect pre-registered singletons in preDetermineBeanTypes as well

Closes gh-33668
This commit is contained in:
Juergen Hoeller
2024-10-08 16:50:12 +02:00
parent c4b6a02091
commit f590511112

View File

@@ -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);
}