|
23 | 23 | import org.springframework.beans.factory.ListableBeanFactory;
|
24 | 24 | import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
25 | 25 | import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
|
| 26 | +import org.springframework.beans.factory.config.DependencyDescriptor; |
| 27 | +import org.springframework.beans.factory.support.DefaultListableBeanFactory; |
26 | 28 | import org.springframework.boot.convert.ApplicationConversionService;
|
27 | 29 | import org.springframework.context.ApplicationContext;
|
28 | 30 | import org.springframework.context.ConfigurableApplicationContext;
|
29 | 31 | import org.springframework.core.convert.ConversionService;
|
30 | 32 | import org.springframework.core.convert.converter.Converter;
|
31 | 33 | import org.springframework.core.convert.converter.GenericConverter;
|
| 34 | +import org.springframework.util.ReflectionUtils; |
32 | 35 |
|
33 | 36 | /**
|
34 | 37 | * Utility to deduce the {@link ConversionService} to use for configuration properties
|
@@ -58,6 +61,9 @@ public ConversionService getConversionService() {
|
58 | 61 |
|
59 | 62 | private static class Factory {
|
60 | 63 |
|
| 64 | + private static DependencyDescriptor DUMMY = new DependencyDescriptor( |
| 65 | + ReflectionUtils.findField(Factory.class, "genericConverters"), false); |
| 66 | + |
61 | 67 | /**
|
62 | 68 | * A list of custom converters (in addition to the defaults) to use when
|
63 | 69 | * converting properties for binding.
|
@@ -85,6 +91,13 @@ private static <T> List<T> beans(BeanFactory beanFactory, Class<T> type,
|
85 | 91 | return list;
|
86 | 92 | }
|
87 | 93 | ListableBeanFactory listable = (ListableBeanFactory) beanFactory;
|
| 94 | + if (listable instanceof DefaultListableBeanFactory) { |
| 95 | + for (String name : listable.getBeanNamesForType(type)) { |
| 96 | + // Force bean definition to resolve its factory method |
| 97 | + ((DefaultListableBeanFactory) listable).isAutowireCandidate(name, |
| 98 | + DUMMY); |
| 99 | + } |
| 100 | + } |
88 | 101 | list.addAll(BeanFactoryAnnotationUtils
|
89 | 102 | .qualifiedBeansOfType(listable, type, qualifier).values());
|
90 | 103 | return list;
|
|
0 commit comments