Config Dubbo Properties Like SpringBoot: ${property_name:default_value} (#512)
diff --git a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/DubboUtils.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/DubboUtils.java
index 59cde99..5973084 100644
--- a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/DubboUtils.java
+++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/DubboUtils.java
@@ -16,6 +16,7 @@
*/
package com.alibaba.boot.dubbo.util;
+import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver;
import org.springframework.core.env.ConfigurableEnvironment;
import java.util.Collections;
@@ -123,6 +124,8 @@
SortedMap<String, Object> dubboProperties = new TreeMap<>();
+ PropertySourcesPlaceholdersResolver resolver = new PropertySourcesPlaceholdersResolver(environment);
+
Map<String, Object> properties = EnvironmentUtils.extractProperties(environment);
for (Map.Entry<String, Object> entry : properties.entrySet()) {
@@ -130,7 +133,7 @@
if (propertyName.startsWith(DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR)
&& entry.getValue() != null) {
- dubboProperties.put(propertyName, entry.getValue().toString());
+ dubboProperties.put(propertyName, resolver.resolvePlaceholders(entry.getValue()));
}
}
diff --git a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/EnvironmentUtils.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/EnvironmentUtils.java
index 9b20c58..bf1ade1 100644
--- a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/EnvironmentUtils.java
+++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/util/EnvironmentUtils.java
@@ -64,7 +64,8 @@
for (PropertySource<?> source : map.values()) {
- if (source instanceof EnumerablePropertySource) {
+ if (source instanceof EnumerablePropertySource
+ && !source.getName().equals("systemEnvironment")) {
EnumerablePropertySource propertySource = (EnumerablePropertySource) source;
diff --git a/pom.xml b/pom.xml
index a223d60..2e74a03 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,7 +37,7 @@
<properties>
<maven_javadoc_version>3.0.1</maven_javadoc_version>
<maven_surefire_version>2.19.1</maven_surefire_version>
- <revision>0.2.1</revision>
+ <revision>0.2.2</revision>
</properties>
<modules>