mercyblitz closed pull request #1895: support placeholders in properties.
URL: https://github.com/apache/incubator-dubbo/pull/1895
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 5b183e1f2f..c9a4d12cd9 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 @@
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 @@
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 5dd526f7bc..2840ecf145 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 void testGetSubProperties() {
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);
+
}
}
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]