Skip to content

Commit b3d4af6

Browse files
author
Dave Syer
committed
Force factory method to be resolved
SPR-8891 is still in flux. It might settle down so we don't need the hack, but for now this is needed to make the factory method for converter beans available in time to select them by qualifier.
1 parent 06ca7e3 commit b3d4af6

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConversionServiceDeducer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
import org.springframework.beans.factory.ListableBeanFactory;
2424
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2525
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
26+
import org.springframework.beans.factory.config.DependencyDescriptor;
27+
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
2628
import org.springframework.boot.convert.ApplicationConversionService;
2729
import org.springframework.context.ApplicationContext;
2830
import org.springframework.context.ConfigurableApplicationContext;
2931
import org.springframework.core.convert.ConversionService;
3032
import org.springframework.core.convert.converter.Converter;
3133
import org.springframework.core.convert.converter.GenericConverter;
34+
import org.springframework.util.ReflectionUtils;
3235

3336
/**
3437
* Utility to deduce the {@link ConversionService} to use for configuration properties
@@ -58,6 +61,9 @@ public ConversionService getConversionService() {
5861

5962
private static class Factory {
6063

64+
private static DependencyDescriptor DUMMY = new DependencyDescriptor(
65+
ReflectionUtils.findField(Factory.class, "genericConverters"), false);
66+
6167
/**
6268
* A list of custom converters (in addition to the defaults) to use when
6369
* converting properties for binding.
@@ -85,6 +91,13 @@ private static <T> List<T> beans(BeanFactory beanFactory, Class<T> type,
8591
return list;
8692
}
8793
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+
}
88101
list.addAll(BeanFactoryAnnotationUtils
89102
.qualifiedBeansOfType(listable, type, qualifier).values());
90103
return list;

0 commit comments

Comments
 (0)