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 c4bc848e2c9..fe1c61bbbde 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 @@ -52,9 +52,7 @@ public static Map getSubProperties(PropertySources propertySourc if (name.startsWith(normalizedPrefix)) { String subName = name.substring(normalizedPrefix.length()); Object value = source.getProperty(name); - if (value instanceof String) { - subProperties.put(subName, String.valueOf(value)); - } + subProperties.put(subName, String.valueOf(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 8377e9f1fed..5dd526f7bcf 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 @@ -44,19 +44,21 @@ public void testGetSubProperties() { propertySources.addFirst(propertySource); - Map result = PropertySourcesUtils.getSubProperties(propertySources, "user"); + String KEY_PREFIX = "user"; + String KEY_NAME = "name"; + String KEY_AGE = "age"; + Map result = PropertySourcesUtils.getSubProperties(propertySources, KEY_PREFIX); Assert.assertEquals(Collections.emptyMap(), result); - source.put("user.name", "Mercy"); - source.put("user.age", "31"); + source.put(KEY_PREFIX + "." + KEY_NAME, "Mercy"); + source.put(KEY_PREFIX + "." + KEY_AGE, 31); Map expected = new HashMap(); - expected.put("name", "Mercy"); - expected.put("age", "31"); - - result = PropertySourcesUtils.getSubProperties(propertySources, "user"); + expected.put(KEY_NAME, "Mercy"); + expected.put(KEY_AGE, "31"); + result = PropertySourcesUtils.getSubProperties(propertySources, KEY_PREFIX); Assert.assertEquals(expected, result); result = PropertySourcesUtils.getSubProperties(propertySources, "");