|
18 | 18 |
|
19 | 19 | import java.lang.annotation.Annotation;
|
20 | 20 | import java.lang.reflect.AnnotatedElement;
|
| 21 | +import java.lang.reflect.Constructor; |
21 | 22 | import java.lang.reflect.Method;
|
22 | 23 | import java.util.Iterator;
|
23 | 24 | import java.util.LinkedHashMap;
|
|
30 | 31 | import org.springframework.beans.factory.config.BeanPostProcessor;
|
31 | 32 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
32 | 33 | import org.springframework.beans.factory.support.RootBeanDefinition;
|
| 34 | +import org.springframework.boot.context.properties.bind.BindConstructorProvider; |
33 | 35 | import org.springframework.boot.context.properties.bind.Bindable;
|
34 | 36 | import org.springframework.boot.context.properties.bind.Binder;
|
35 | 37 | import org.springframework.context.ApplicationContext;
|
@@ -70,8 +72,8 @@ public final class ConfigurationPropertiesBean {
|
70 | 72 | private final BindMethod bindMethod;
|
71 | 73 |
|
72 | 74 | private ConfigurationPropertiesBean(String name, Object instance, ConfigurationProperties annotation,
|
73 |
| - Bindable<?> bindTarget) { |
74 |
| - this(name, instance, annotation, bindTarget, BindMethod.forType(bindTarget.getType().resolve())); |
| 75 | + Bindable<?> bindable) { |
| 76 | + this(name, instance, annotation, bindable, BindMethod.get(bindable)); |
75 | 77 | }
|
76 | 78 |
|
77 | 79 | private ConfigurationPropertiesBean(String name, Object instance, ConfigurationProperties annotation,
|
@@ -274,14 +276,14 @@ private static ConfigurationPropertiesBean create(String name, Object instance,
|
274 | 276 | : new Annotation[] { annotation };
|
275 | 277 | ResolvableType bindType = (factory != null) ? ResolvableType.forMethodReturnType(factory)
|
276 | 278 | : ResolvableType.forClass(type);
|
277 |
| - Bindable<Object> bindTarget = Bindable.of(bindType).withAnnotations(annotations); |
| 279 | + Bindable<Object> bindable = Bindable.of(bindType).withAnnotations(annotations); |
278 | 280 | if (instance != null) {
|
279 |
| - bindTarget = bindTarget.withExistingValue(instance); |
| 281 | + bindable = bindable.withExistingValue(instance); |
280 | 282 | }
|
281 | 283 | if (factory != null) {
|
282 |
| - return new ConfigurationPropertiesBean(name, instance, annotation, bindTarget, BindMethod.JAVA_BEAN); |
| 284 | + return new ConfigurationPropertiesBean(name, instance, annotation, bindable, BindMethod.JAVA_BEAN); |
283 | 285 | }
|
284 |
| - return new ConfigurationPropertiesBean(name, instance, annotation, bindTarget); |
| 286 | + return new ConfigurationPropertiesBean(name, instance, annotation, bindable); |
285 | 287 | }
|
286 | 288 |
|
287 | 289 | private static <A extends Annotation> A findAnnotation(Object instance, Class<?> type, Method factory,
|
@@ -321,9 +323,16 @@ public enum BindMethod {
|
321 | 323 | */
|
322 | 324 | VALUE_OBJECT;
|
323 | 325 |
|
324 |
| - static BindMethod forType(Class<?> type) { |
325 |
| - return (ConfigurationPropertiesBindConstructorProvider.INSTANCE.getBindConstructor(type, false) != null) |
326 |
| - ? VALUE_OBJECT : JAVA_BEAN; |
| 326 | + static BindMethod get(Class<?> type) { |
| 327 | + return get(BindConstructorProvider.DEFAULT.getBindConstructor(type, false)); |
| 328 | + } |
| 329 | + |
| 330 | + static BindMethod get(Bindable<?> bindable) { |
| 331 | + return get(BindConstructorProvider.DEFAULT.getBindConstructor(bindable, false)); |
| 332 | + } |
| 333 | + |
| 334 | + private static BindMethod get(Constructor<?> bindConstructor) { |
| 335 | + return (bindConstructor != null) ? VALUE_OBJECT : JAVA_BEAN; |
327 | 336 | }
|
328 | 337 |
|
329 | 338 | }
|
|
0 commit comments