|
16 | 16 | */
|
17 | 17 | package org.apache.dubbo.spring.boot.autoconfigure;
|
18 | 18 |
|
19 |
| -import org.apache.dubbo.config.AbstractConfig; |
20 |
| -import org.apache.dubbo.config.spring.context.properties.AbstractDubboConfigBinder; |
21 | 19 | import org.apache.dubbo.config.spring.context.properties.DubboConfigBinder;
|
| 20 | + |
| 21 | +import com.alibaba.spring.context.config.ConfigurationBeanBinder; |
22 | 22 | import org.springframework.boot.context.properties.bind.BindHandler;
|
23 | 23 | import org.springframework.boot.context.properties.bind.Bindable;
|
24 | 24 | import org.springframework.boot.context.properties.bind.Binder;
|
|
27 | 27 | import org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler;
|
28 | 28 | import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
|
29 | 29 | import org.springframework.boot.context.properties.source.UnboundElementsSourceFilter;
|
| 30 | +import org.springframework.core.env.MapPropertySource; |
30 | 31 | import org.springframework.core.env.PropertySource;
|
31 | 32 |
|
| 33 | +import java.util.Map; |
| 34 | + |
| 35 | +import static java.util.Arrays.asList; |
32 | 36 | import static org.springframework.boot.context.properties.source.ConfigurationPropertySources.from;
|
33 | 37 |
|
34 | 38 | /**
|
|
37 | 41 | *
|
38 | 42 | * @since 2.7.0
|
39 | 43 | */
|
40 |
| -class BinderDubboConfigBinder extends AbstractDubboConfigBinder { |
| 44 | +class BinderDubboConfigBinder implements ConfigurationBeanBinder { |
41 | 45 |
|
42 | 46 | @Override
|
43 |
| - public <C extends AbstractConfig> void bind(String prefix, C dubboConfig) { |
| 47 | + public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields, |
| 48 | + boolean ignoreInvalidFields, Object configurationBean) { |
44 | 49 |
|
45 |
| - Iterable<PropertySource<?>> propertySources = getPropertySources(); |
| 50 | + Iterable<PropertySource<?>> propertySources = asList(new MapPropertySource("internal", configurationProperties)); |
46 | 51 |
|
47 | 52 | // Converts ConfigurationPropertySources
|
48 | 53 | Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources);
|
49 | 54 |
|
50 | 55 | // Wrap Bindable from DubboConfig instance
|
51 |
| - Bindable<C> bindable = Bindable.ofInstance(dubboConfig); |
| 56 | + Bindable bindable = Bindable.ofInstance(configurationBean); |
52 | 57 |
|
53 | 58 | Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources));
|
54 | 59 |
|
55 | 60 | // Get BindHandler
|
56 |
| - BindHandler bindHandler = getBindHandler(); |
| 61 | + BindHandler bindHandler = getBindHandler(ignoreUnknownFields, ignoreInvalidFields); |
57 | 62 |
|
58 | 63 | // Bind
|
59 |
| - binder.bind(prefix, bindable, bindHandler); |
60 |
| - |
| 64 | + binder.bind("", bindable, bindHandler); |
61 | 65 | }
|
62 | 66 |
|
63 |
| - private BindHandler getBindHandler() { |
| 67 | + private BindHandler getBindHandler(boolean ignoreUnknownFields, |
| 68 | + boolean ignoreInvalidFields) { |
64 | 69 | BindHandler handler = BindHandler.DEFAULT;
|
65 |
| - if (isIgnoreInvalidFields()) { |
| 70 | + if (ignoreInvalidFields) { |
66 | 71 | handler = new IgnoreErrorsBindHandler(handler);
|
67 | 72 | }
|
68 |
| - if (!isIgnoreUnknownFields()) { |
| 73 | + if (!ignoreUnknownFields) { |
69 | 74 | UnboundElementsSourceFilter filter = new UnboundElementsSourceFilter();
|
70 | 75 | handler = new NoUnboundElementsBindHandler(handler, filter);
|
71 | 76 | }
|
|
0 commit comments