This is an automated email from the ASF dual-hosted git repository. mercyblitz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push: new c459f6c support resolves property values. (#1895) c459f6c is described below commit c459f6c9afc43154fd9a9838f2dc96297dd0ce4d Author: wuwen <wuwen...@aliyun.com> AuthorDate: Fri Jun 8 11:12:31 2018 +0800 support resolves property values. (#1895) Ok for me --- .../alibaba/dubbo/config/spring/util/PropertySourcesUtils.java | 7 +++++-- .../dubbo/config/spring/util/PropertySourcesUtilsTest.java | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/util/PropertySourcesUtils.java b/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/util/PropertySourcesUtils.java index 5b183e1..c9a4d12 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/util/PropertySourcesUtils.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/com/alibaba/dubbo/config/spring/util/PropertySourcesUtils.java @@ -19,6 +19,7 @@ package com.alibaba.dubbo.config.spring.util; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySources; +import org.springframework.core.env.PropertySourcesPropertyResolver; import java.util.LinkedHashMap; import java.util.Map; @@ -46,13 +47,15 @@ public abstract class PropertySourcesUtils { String normalizedPrefix = normalizePrefix(prefix); + PropertySourcesPropertyResolver propertyResolver = new PropertySourcesPropertyResolver((PropertySources) propertySources); + for (PropertySource<?> source : propertySources) { if (source instanceof EnumerablePropertySource) { for (String name : ((EnumerablePropertySource<?>) source).getPropertyNames()) { if (name.startsWith(normalizedPrefix)) { String subName = name.substring(normalizedPrefix.length()); - Object value = source.getProperty(name); - subProperties.put(subName, String.valueOf(value)); + String value = propertyResolver.getProperty(name); + subProperties.put(subName, value); } } } diff --git a/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/util/PropertySourcesUtilsTest.java b/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/util/PropertySourcesUtilsTest.java index 5dd526f..2840ecf 100644 --- a/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/util/PropertySourcesUtilsTest.java +++ b/dubbo-config/dubbo-config-spring/src/test/java/com/alibaba/dubbo/config/spring/util/PropertySourcesUtilsTest.java @@ -69,6 +69,15 @@ public class PropertySourcesUtilsTest { Assert.assertEquals(Collections.emptyMap(), result); + source.put(KEY_PREFIX + ".app.name", "${info.name}"); + source.put("info.name", "Hello app"); + + result = PropertySourcesUtils.getSubProperties(propertySources, KEY_PREFIX); + + String appName = result.get("app.name"); + + Assert.assertEquals("Hello app", appName); + } } -- To stop receiving notification emails like this one, please contact mercybl...@apache.org.