diff --git a/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java index ae747074c5..f76668f4eb 100644 --- a/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java @@ -425,25 +425,37 @@ public class GenericApplicationContext extends AbstractApplicationContext implem * @see SmartInstantiationAwareBeanPostProcessor#determineBeanType */ private void preDetermineBeanTypes(RuntimeHints runtimeHints) { + List singletons = new ArrayList<>(); + List 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 bpps = PostProcessorRegistrationDelegate.loadBeanPostProcessors( this.beanFactory, SmartInstantiationAwareBeanPostProcessor.class); - List 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); }