diff --git a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfiguration.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfiguration.java index 11ea77783..781900c33 100644 --- a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfiguration.java +++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfiguration.java @@ -40,7 +40,9 @@ import java.util.Set; import static com.alibaba.boot.dubbo.util.DubboUtils.BASE_PACKAGES_PROPERTY_NAME; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_CONFIG_PREFIX; import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_PREFIX; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SCAN_PREFIX; import static com.alibaba.boot.dubbo.util.DubboUtils.MULTIPLE_CONFIG_PROPERTY_NAME; import static java.util.Collections.emptySet; import static org.springframework.beans.factory.config.ConfigurableBeanFactory.SCOPE_PROTOTYPE; @@ -78,7 +80,7 @@ protected static class SingleDubboConfigConfiguration { * @see EnableDubboConfig * @see DubboConfigConfiguration.Multiple */ - @ConditionalOnProperty(name = MULTIPLE_CONFIG_PROPERTY_NAME, havingValue = "true") + @ConditionalOnProperty(prefix = DUBBO_CONFIG_PREFIX, name = MULTIPLE_CONFIG_PROPERTY_NAME, havingValue = "true") @EnableDubboConfig(multiple = true) protected static class MultipleDubboConfigConfiguration { } @@ -89,11 +91,11 @@ protected static class MultipleDubboConfigConfiguration { * @param environment {@link Environment} Bean * @return {@link ServiceAnnotationBeanPostProcessor} */ - @ConditionalOnProperty(name = BASE_PACKAGES_PROPERTY_NAME) + @ConditionalOnProperty(prefix = DUBBO_SCAN_PREFIX, name = BASE_PACKAGES_PROPERTY_NAME) @ConditionalOnClass(RelaxedPropertyResolver.class) @Bean public ServiceAnnotationBeanPostProcessor serviceAnnotationBeanPostProcessor(Environment environment) { - RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment); + RelaxedPropertyResolver resolver = new RelaxedPropertyResolver(environment, DUBBO_SCAN_PREFIX); Set packagesToScan = resolver.getProperty(BASE_PACKAGES_PROPERTY_NAME, Set.class, emptySet()); return new ServiceAnnotationBeanPostProcessor(packagesToScan); } diff --git a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListener.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListener.java index e39ea5050..283081b06 100644 --- a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListener.java +++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListener.java @@ -17,7 +17,6 @@ package com.alibaba.boot.dubbo.context.event; import com.alibaba.dubbo.common.utils.ConfigUtils; - import com.alibaba.dubbo.config.AbstractConfig; import org.slf4j.Logger; @@ -31,6 +30,7 @@ import java.util.SortedMap; import static com.alibaba.boot.dubbo.util.DubboUtils.DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_CONFIG_PREFIX; import static com.alibaba.boot.dubbo.util.DubboUtils.OVERRIDE_CONFIG_PROPERTY_NAME; import static com.alibaba.boot.dubbo.util.DubboUtils.filterDubboProperties; @@ -57,8 +57,8 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { ConfigurableEnvironment environment = event.getEnvironment(); - boolean override = environment.getProperty(OVERRIDE_CONFIG_PROPERTY_NAME, boolean.class, - DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE); + boolean override = environment.getProperty(DUBBO_CONFIG_PREFIX + OVERRIDE_CONFIG_PROPERTY_NAME, + boolean.class, DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE); if (override) { 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 71fac05d5..1c38c0d8a 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 @@ -45,31 +45,31 @@ public abstract class DubboUtils { /** * The prefix of property name of Dubbo */ - public static final String DUBBO_PREFIX = "dubbo"; + public static final String DUBBO_PREFIX = "dubbo" + PROPERTY_NAME_SEPARATOR; /** * The prefix of property name for Dubbo scan */ - public static final String DUBBO_SCAN_PREFIX = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + "scan"; + public static final String DUBBO_SCAN_PREFIX = DUBBO_PREFIX + "scan" + PROPERTY_NAME_SEPARATOR; /** * The prefix of property name for Dubbo Config.ØØ */ - public static final String DUBBO_CONFIG_PREFIX = DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR + "config"; + public static final String DUBBO_CONFIG_PREFIX = DUBBO_PREFIX + "config" + PROPERTY_NAME_SEPARATOR; /** * The property name of base packages to scan *

* The default value is empty set. */ - public static final String BASE_PACKAGES_PROPERTY_NAME = DUBBO_SCAN_PREFIX + PROPERTY_NAME_SEPARATOR + "base-packages"; + public static final String BASE_PACKAGES_PROPERTY_NAME = "base-packages"; /** * The property name of multiple properties binding from externalized configuration *

* The default value is {@link #DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE} */ - public static final String MULTIPLE_CONFIG_PROPERTY_NAME = DUBBO_CONFIG_PREFIX + PROPERTY_NAME_SEPARATOR + "multiple"; + public static final String MULTIPLE_CONFIG_PROPERTY_NAME = "multiple"; /** * The default value of multiple properties binding from externalized configuration @@ -81,7 +81,7 @@ public abstract class DubboUtils { *

* The default value is {@link #DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE} */ - public static final String OVERRIDE_CONFIG_PROPERTY_NAME = DUBBO_CONFIG_PREFIX + PROPERTY_NAME_SEPARATOR + "override"; + public static final String OVERRIDE_CONFIG_PROPERTY_NAME = "override"; /** * The default property value of override Dubbo config @@ -129,7 +129,7 @@ public static SortedMap filterDubboProperties(ConfigurableEnviro for (Map.Entry entry : properties.entrySet()) { String propertyName = entry.getKey(); - if (propertyName.startsWith(DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR)) { + if (propertyName.startsWith(DUBBO_PREFIX)) { dubboProperties.put(propertyName, entry.getValue()); } diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/DubboUtilsTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/DubboUtilsTest.java index 40fd6bc3c..f00f23f2c 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/DubboUtilsTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/DubboUtilsTest.java @@ -39,7 +39,6 @@ /** * {@link DubboUtils} Test - *Ø * @author Mercy * @see DubboUtils * @since 1.0.0 @@ -49,17 +48,17 @@ public class DubboUtilsTest { @Test public void testConstants() { - Assert.assertEquals("dubbo", DUBBO_PREFIX); + Assert.assertEquals("dubbo.", DUBBO_PREFIX); - Assert.assertEquals("dubbo.scan", DUBBO_SCAN_PREFIX); + Assert.assertEquals("dubbo.scan.", DUBBO_SCAN_PREFIX); - Assert.assertEquals("dubbo.scan.base-packages", BASE_PACKAGES_PROPERTY_NAME); + Assert.assertEquals("dubbo.scan.base-packages", DUBBO_SCAN_PREFIX + BASE_PACKAGES_PROPERTY_NAME); - Assert.assertEquals("dubbo.config", DUBBO_CONFIG_PREFIX); + Assert.assertEquals("dubbo.config.", DUBBO_CONFIG_PREFIX); - Assert.assertEquals("dubbo.config.multiple", MULTIPLE_CONFIG_PROPERTY_NAME); + Assert.assertEquals("dubbo.config.multiple", DUBBO_CONFIG_PREFIX + MULTIPLE_CONFIG_PROPERTY_NAME); - Assert.assertEquals("dubbo.config.override", OVERRIDE_CONFIG_PROPERTY_NAME); + Assert.assertEquals("dubbo.config.override", DUBBO_CONFIG_PREFIX + OVERRIDE_CONFIG_PROPERTY_NAME); Assert.assertEquals("https://github.com/apache/incubator-dubbo-spring-boot-project", DUBBO_SPRING_BOOT_GITHUB_URL); Assert.assertEquals("https://github.com/apache/incubator-dubbo-spring-boot-project.git", DUBBO_SPRING_BOOT_GIT_URL); @@ -81,13 +80,13 @@ public void testFilterDubboProperties() { MockEnvironment environment = new MockEnvironment(); environment.setProperty("message", "Hello,World"); - environment.setProperty(MULTIPLE_CONFIG_PROPERTY_NAME, "true"); - environment.setProperty(OVERRIDE_CONFIG_PROPERTY_NAME, "true"); + environment.setProperty(DUBBO_CONFIG_PREFIX + MULTIPLE_CONFIG_PROPERTY_NAME, "true"); + environment.setProperty(DUBBO_CONFIG_PREFIX + OVERRIDE_CONFIG_PROPERTY_NAME, "true"); SortedMap dubboProperties = filterDubboProperties(environment); - Assert.assertEquals("true",dubboProperties.get(MULTIPLE_CONFIG_PROPERTY_NAME)); - Assert.assertEquals("true",dubboProperties.get(OVERRIDE_CONFIG_PROPERTY_NAME)); + Assert.assertEquals("true", dubboProperties.get(DUBBO_CONFIG_PREFIX + MULTIPLE_CONFIG_PROPERTY_NAME)); + Assert.assertEquals("true", dubboProperties.get(DUBBO_CONFIG_PREFIX + OVERRIDE_CONFIG_PROPERTY_NAME)); }