@@ -425,25 +425,37 @@ public void refreshForAotProcessing(RuntimeHints runtimeHints) {
425
425
* @see SmartInstantiationAwareBeanPostProcessor#determineBeanType
426
426
*/
427
427
private void preDetermineBeanTypes (RuntimeHints runtimeHints ) {
428
+ List <String > singletons = new ArrayList <>();
429
+ List <String > lazyBeans = new ArrayList <>();
430
+
431
+ // First round: pre-registered singleton instances, if any.
432
+ for (String beanName : this .beanFactory .getSingletonNames ()) {
433
+ Class <?> beanType = this .beanFactory .getType (beanName );
434
+ if (beanType != null ) {
435
+ ClassHintUtils .registerProxyIfNecessary (beanType , runtimeHints );
436
+ }
437
+ singletons .add (beanName );
438
+ }
439
+
428
440
List <SmartInstantiationAwareBeanPostProcessor > bpps =
429
441
PostProcessorRegistrationDelegate .loadBeanPostProcessors (
430
442
this .beanFactory , SmartInstantiationAwareBeanPostProcessor .class );
431
443
432
- List <String > lazyBeans = new ArrayList <>();
433
-
434
- // First round: non-lazy singleton beans in definition order,
444
+ // Second round: non-lazy singleton beans in definition order,
435
445
// matching preInstantiateSingletons.
436
446
for (String beanName : this .beanFactory .getBeanDefinitionNames ()) {
437
- BeanDefinition bd = getBeanDefinition (beanName );
438
- if (bd .isSingleton () && !bd .isLazyInit ()) {
439
- preDetermineBeanType (beanName , bpps , runtimeHints );
440
- }
441
- else {
442
- lazyBeans .add (beanName );
447
+ if (!singletons .contains (beanName )) {
448
+ BeanDefinition bd = getBeanDefinition (beanName );
449
+ if (bd .isSingleton () && !bd .isLazyInit ()) {
450
+ preDetermineBeanType (beanName , bpps , runtimeHints );
451
+ }
452
+ else {
453
+ lazyBeans .add (beanName );
454
+ }
443
455
}
444
456
}
445
457
446
- // Second round: lazy singleton beans and scoped beans.
458
+ // Third round: lazy singleton beans and scoped beans.
447
459
for (String beanName : lazyBeans ) {
448
460
preDetermineBeanType (beanName , bpps , runtimeHints );
449
461
}
0 commit comments