*
* registry=com.alibaba.dubbo.registry.status.RegistryStatusChecker * spring=com.alibaba.dubbo.config.spring.status.SpringStatusChecker diff --git a/dubbo-spring-boot-actuator/src/main/resources/META-INF/dubbo-endpoins-default.properties b/dubbo-spring-boot-actuator/src/main/resources/META-INF/dubbo-endpoins-default.properties index 97a012feb..99215bfcd 100644 --- a/dubbo-spring-boot-actuator/src/main/resources/META-INF/dubbo-endpoins-default.properties +++ b/dubbo-spring-boot-actuator/src/main/resources/META-INF/dubbo-endpoins-default.properties @@ -4,19 +4,19 @@ # Set enabled for Dubbo Endpoints management.endpoint.dubbo.enabled = true -management.endpoint.dubbo-shutdown.enabled = false -management.endpoint.dubbo-configs.enabled = true -management.endpoint.dubbo-services.enabled = false -management.endpoint.dubbo-references.enabled = false -management.endpoint.dubbo-properties.enabled = true +management.endpoint.dubboShutdown.enabled = false +management.endpoint.dubboConfigs.enabled = true +management.endpoint.dubboServices.enabled = false +management.endpoint.dubboReferences.enabled = false +management.endpoint.dubboProperties.enabled = true # "management.endpoints.web.base-path" should not be configured in this file # Re-defines path-mapping of Dubbo Web Endpoints -management.endpoints.web.path-mapping.dubbo-shutdown = dubbo/shutdown -management.endpoints.web.path-mapping.dubbo-configs = dubbo/configs -management.endpoints.web.path-mapping.dubbo-services = dubbo/services -management.endpoints.web.path-mapping.dubbo-references = dubbo/references -management.endpoints.web.path-mapping.dubbo-properties = dubbo/properties +management.endpoints.web.path-mapping.dubboShutdown = dubbo/shutdown +management.endpoints.web.path-mapping.dubboConfigs = dubbo/configs +management.endpoints.web.path-mapping.dubboServices = dubbo/services +management.endpoints.web.path-mapping.dubboReferences = dubbo/references +management.endpoints.web.path-mapping.dubboProperties = dubbo/properties diff --git a/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointTest.java b/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointTest.java index 0135ec331..e1aa531f0 100644 --- a/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointTest.java +++ b/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointTest.java @@ -17,12 +17,12 @@ package com.alibaba.boot.dubbo.actuate.endpoint; import com.alibaba.boot.dubbo.util.DubboUtils; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringRunner; import java.util.Map; diff --git a/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointsAutoConfigurationTest.java b/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointsAutoConfigurationTest.java index 9bd190be1..3576dbafe 100644 --- a/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointsAutoConfigurationTest.java +++ b/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpointsAutoConfigurationTest.java @@ -18,6 +18,7 @@ import com.alibaba.boot.dubbo.actuate.autoconfigure.DubboEndpointsAutoConfiguration; import com.alibaba.dubbo.config.annotation.Service; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -57,11 +58,11 @@ "dubbo.provider.host=127.0.0.1", "dubbo.scan.basePackages=com.alibaba.boot.dubbo.actuate.endpoint", "management.endpoint.dubbo.enabled = true", - "management.endpoint.dubbo-shutdown.enabled = true", - "management.endpoint.dubbo-configs.enabled = true", - "management.endpoint.dubbo-services.enabled = true", - "management.endpoint.dubbo-references.enabled = true", - "management.endpoint.dubbo-properties.enabled = true", + "management.endpoint.dubboShutdown.enabled = true", + "management.endpoint.dubboConfigs.enabled = true", + "management.endpoint.dubboServices.enabled = true", + "management.endpoint.dubboReferences.enabled = true", + "management.endpoint.dubboProperties.enabled = true", }) @EnableAutoConfiguration public class DubboEndpointsAutoConfigurationTest { @@ -143,7 +144,7 @@ public void testServices() { Assert.assertEquals(1, services.size()); - MapdemoServiceMeta = services.get("ServiceBean:dubboEndpointsAutoConfigurationTest.DefaultDemoService:com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpointsAutoConfigurationTest$DemoService:${dubbo.service.version}"); + Map demoServiceMeta = services.get("ServiceBean:com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpointsAutoConfigurationTest$DemoService:1.0.0"); Assert.assertEquals("1.0.0", demoServiceMeta.get("version")); diff --git a/dubbo-spring-boot-autoconfigure/README.md b/dubbo-spring-boot-autoconfigure/README.md index b5e9306ff..d75b8a1f4 100644 --- a/dubbo-spring-boot-autoconfigure/README.md +++ b/dubbo-spring-boot-autoconfigure/README.md @@ -23,7 +23,7 @@ You can introduce the latest `dubbo-spring-boot-autoconfigure` to your project ``` diff --git a/dubbo-spring-boot-autoconfigure/pom.xml b/dubbo-spring-boot-autoconfigure/pom.xml index 1e892fa1c..ae2bae3fd 100644 --- a/dubbo-spring-boot-autoconfigure/pom.xml +++ b/dubbo-spring-boot-autoconfigure/pom.xml @@ -38,6 +38,7 @@ com.alibaba.boot dubbo-spring-boot-autoconfigure -0.2.0 +0.2.1-SNAPSHOT spring-boot-autoconfigure true ++ + org.springframework.boot spring-boot-starter-logging @@ -58,11 +59,18 @@true + +com.alibaba.spring +spring-context-support ++ \ No newline at end of file diff --git a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinder.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinder.java index def20f000..51a6ab72f 100644 --- a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinder.java +++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinder.java @@ -19,13 +19,16 @@ import com.alibaba.dubbo.config.AbstractConfig; import com.alibaba.dubbo.config.spring.context.properties.AbstractDubboConfigBinder; import com.alibaba.dubbo.config.spring.context.properties.DubboConfigBinder; + import org.springframework.boot.context.properties.bind.BindHandler; import org.springframework.boot.context.properties.bind.Bindable; import org.springframework.boot.context.properties.bind.Binder; +import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver; import org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler; import org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler; import org.springframework.boot.context.properties.source.ConfigurationPropertySource; import org.springframework.boot.context.properties.source.UnboundElementsSourceFilter; +import org.springframework.core.env.PropertySource; import static org.springframework.boot.context.properties.source.ConfigurationPropertySources.from; @@ -41,13 +44,15 @@ public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder { @Override public org.springframework.boot spring-boot-starter-test test void bind(String prefix, C dubboConfig) { + Iterable > propertySources = getPropertySources(); + // Converts ConfigurationPropertySources - Iterable propertySources = from(getPropertySources()); + Iterable configurationPropertySources = from(propertySources); // Wrap Bindable from DubboConfig instance Bindable bindable = Bindable.ofInstance(dubboConfig); - Binder binder = new Binder(propertySources); + Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources)); // Get BindHandler BindHandler bindHandler = getBindHandler(); diff --git a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListener.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListener.java index ae9682c81..99cf9808a 100644 --- a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListener.java +++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListener.java @@ -17,6 +17,7 @@ package com.alibaba.boot.dubbo.context.event; import com.alibaba.dubbo.common.Version; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; @@ -24,8 +25,12 @@ import org.springframework.context.ApplicationListener; import org.springframework.core.annotation.Order; -import static com.alibaba.boot.dubbo.util.DubboUtils.*; -import static com.alibaba.dubbo.qos.server.DubboLogo.dubbo; +import java.util.concurrent.atomic.AtomicBoolean; + +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_GITHUB_URL; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_MAILING_LIST; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GITHUB_URL; +import static com.alibaba.boot.dubbo.util.DubboUtils.LINE_SEPARATOR; /** * Dubbo Welcome Logo {@link ApplicationListener} @@ -37,10 +42,16 @@ @Order(LoggingApplicationListener.DEFAULT_ORDER + 1) public class WelcomeLogoApplicationListener implements ApplicationListener { + private static AtomicBoolean processed = new AtomicBoolean(false); @Override public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { + // Skip if processed before, prevent duplicated execution in Hierarchical ApplicationContext + if (processed.get()) { + return; + } + /** * Gets Logger After LoggingSystem configuration ready * @see LoggingApplicationListener @@ -55,9 +66,10 @@ public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) { System.out.print(bannerText); } + // mark processed to be true + processed.compareAndSet(false, true); } - String buildBannerText() { StringBuilder bannerTextBuilder = new StringBuilder(); @@ -71,7 +83,7 @@ String buildBannerText() { .append(" :: Dubbo (v").append(Version.getVersion()).append(") : ") .append(DUBBO_GITHUB_URL) .append(LINE_SEPARATOR) - .append(" :: Google group : ") + .append(" :: Discuss group : ") .append(DUBBO_MAILING_LIST) .append(LINE_SEPARATOR) ; diff --git a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java new file mode 100644 index 000000000..d8a671b95 --- /dev/null +++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessor.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.env; + +import com.alibaba.dubbo.config.ApplicationConfig; +import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig; +import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfigBinding; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.context.ContextIdApplicationContextInitializer; +import org.springframework.boot.env.EnvironmentPostProcessor; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.core.Ordered; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +/** + * The lowest precedence {@link EnvironmentPostProcessor} processes + * {@link SpringApplication#setDefaultProperties(Properties) Spring Boot default properties} for Dubbo + * as late as possible before {@link ConfigurableApplicationContext#refresh() application context refresh}. + */ +public class DubboDefaultPropertiesEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { + + /** + * The name of default {@link PropertySource} defined in SpringApplication#configurePropertySources method. + */ + private static final String PROPERTY_SOURCE_NAME = "defaultProperties"; + + /** + * The property name of Spring Application + * + * @see ContextIdApplicationContextInitializer + */ + private static final String SPRING_APPLICATION_NAME_PROPERTY = "spring.application.name"; + + /** + * The property name of {@link ApplicationConfig} + * + * @see EnableDubboConfig + * @see EnableDubboConfigBinding + */ + private static final String DUBBO_APPLICATION_NAME_PROPERTY = "dubbo.application.name"; + + @Override + public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) { + MutablePropertySources propertySources = environment.getPropertySources(); + Map defaultProperties = createDefaultProperties(environment); + if (!CollectionUtils.isEmpty(defaultProperties)) { + addOrReplace(propertySources, defaultProperties); + } + } + + @Override + public int getOrder() { + return LOWEST_PRECEDENCE; + } + + private Map createDefaultProperties(ConfigurableEnvironment environment) { + Map defaultProperties = new HashMap (); + setDubboApplicationNameProperty(environment, defaultProperties); + return defaultProperties; + } + + private void setDubboApplicationNameProperty(Environment environment, Map defaultProperties) { + String springApplicationName = environment.getProperty(SPRING_APPLICATION_NAME_PROPERTY); + if (StringUtils.hasLength(springApplicationName) + && !environment.containsProperty(DUBBO_APPLICATION_NAME_PROPERTY)) { + defaultProperties.put(DUBBO_APPLICATION_NAME_PROPERTY, springApplicationName); + } + } + + /** + * Copy from BusEnvironmentPostProcessor#addOrReplace(MutablePropertySources, Map) + * + * @param propertySources {@link MutablePropertySources} + * @param map Default Dubbo Properties + */ + private void addOrReplace(MutablePropertySources propertySources, + Map map) { + MapPropertySource target = null; + if (propertySources.contains(PROPERTY_SOURCE_NAME)) { + PropertySource> source = propertySources.get(PROPERTY_SOURCE_NAME); + if (source instanceof MapPropertySource) { + target = (MapPropertySource) source; + for (String key : map.keySet()) { + if (!target.containsProperty(key)) { + target.getSource().put(key, map.get(key)); + } + } + } + } + if (target == null) { + target = new MapPropertySource(PROPERTY_SOURCE_NAME, map); + } + if (!propertySources.contains(PROPERTY_SOURCE_NAME)) { + propertySources.addLast(target); + } + } +} \ No newline at end of file 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 edf4ab2cb..7bf2b6966 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,11 +16,12 @@ */ package com.alibaba.boot.dubbo.util; +import org.springframework.core.env.ConfigurableEnvironment; + import java.util.Collections; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; -import org.springframework.core.env.ConfigurableEnvironment; /** * The utilities class for Dubbo @@ -61,7 +62,7 @@ public abstract class DubboUtils { * * The default value is empty set. */ - public static final String BASE_PACKAGES_PROPERTY_NAME = DUBBO_SCAN_PREFIX + PROPERTY_NAME_SEPARATOR + "basePackages"; + public static final String BASE_PACKAGES_PROPERTY_NAME = DUBBO_SCAN_PREFIX + PROPERTY_NAME_SEPARATOR + "base-packages"; /** * The property name of multiple properties binding from externalized configuration diff --git a/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json b/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json index 078dae99d..7ce2ceec9 100644 --- a/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json +++ b/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring-configuration-metadata.json @@ -1090,8 +1090,8 @@ }, { "sourceType": "com.alibaba.boot.dubbo.autoconfigure.DubboScanProperties", - "name": "dubbo.scan.basePackages", - "description": "The basePackages to scan , the multiple-value is delimited by comma\n\n @see EnableDubbo#scanBasePackages()", + "name": "dubbo.scan.base-packages", + "description": "The base-packages to scan , the multiple-value is delimited by comma\n\n @see EnableDubbo#scanBasePackages()", "type": "java.util.Set
" } ] diff --git a/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories b/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories index 52fe93ce2..4ea2a1a98 100644 --- a/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories +++ b/dubbo-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories @@ -5,4 +5,7 @@ com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration org.springframework.context.ApplicationListener=\ com.alibaba.boot.dubbo.context.event.OverrideDubboConfigApplicationListener,\ com.alibaba.boot.dubbo.context.event.WelcomeLogoApplicationListener,\ -com.alibaba.boot.dubbo.context.event.AwaitingNonWebApplicationListener \ No newline at end of file +com.alibaba.boot.dubbo.context.event.AwaitingNonWebApplicationListener + +org.springframework.boot.env.EnvironmentPostProcessor=\ +com.alibaba.boot.dubbo.env.DubboDefaultPropertiesEnvironmentPostProcessor \ No newline at end of file diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java new file mode 100644 index 000000000..626f2c9c6 --- /dev/null +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/env/DubboDefaultPropertiesEnvironmentPostProcessorTest.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.alibaba.boot.dubbo.env; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.SpringApplication; +import org.springframework.core.Ordered; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; +import org.springframework.mock.env.MockEnvironment; + +import java.util.HashMap; + +/** + * {@link DubboDefaultPropertiesEnvironmentPostProcessor} Test + */ +public class DubboDefaultPropertiesEnvironmentPostProcessorTest { + + private DubboDefaultPropertiesEnvironmentPostProcessor instance = + new DubboDefaultPropertiesEnvironmentPostProcessor(); + + private SpringApplication springApplication = new SpringApplication(); + + @Test + public void testOrder() { + Assert.assertEquals(Ordered.LOWEST_PRECEDENCE, instance.getOrder()); + } + + @Test + public void testPostProcessEnvironment() { + MockEnvironment environment = new MockEnvironment(); + // Case 1 : Not Any property + instance.postProcessEnvironment(environment, springApplication); + // Get PropertySources + MutablePropertySources propertySources = environment.getPropertySources(); + // Nothing to change + PropertySource defaultPropertySource = propertySources.get("defaultProperties"); + Assert.assertNull(defaultPropertySource); + + // Case 2 : Only set property "spring.application.name" + environment.setProperty("spring.application.name", "demo-dubbo-application"); + instance.postProcessEnvironment(environment, springApplication); + defaultPropertySource = propertySources.get("defaultProperties"); + Object dubboApplicationName = defaultPropertySource.getProperty("dubbo.application.name"); + Assert.assertEquals("demo-dubbo-application", dubboApplicationName); + + // Case 3 : Only set property "dubbo.application.name" + // Rest environment + environment = new MockEnvironment(); + propertySources = environment.getPropertySources(); + environment.setProperty("dubbo.application.name", "demo-dubbo-application"); + instance.postProcessEnvironment(environment, springApplication); + defaultPropertySource = propertySources.get("defaultProperties"); + Assert.assertNull(defaultPropertySource); + dubboApplicationName = environment.getProperty("dubbo.application.name"); + Assert.assertEquals("demo-dubbo-application", dubboApplicationName); + + // Case 4 : If "defaultProperties" PropertySource is present in PropertySources + // Rest environment + environment = new MockEnvironment(); + propertySources = environment.getPropertySources(); + propertySources.addLast(new MapPropertySource("defaultProperties", new HashMap ())); + environment.setProperty("spring.application.name", "demo-dubbo-application"); + instance.postProcessEnvironment(environment, springApplication); + defaultPropertySource = propertySources.get("defaultProperties"); + dubboApplicationName = defaultPropertySource.getProperty("dubbo.application.name"); + Assert.assertEquals("demo-dubbo-application", dubboApplicationName); + } +} 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 94df5d0e1..af961134e 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 @@ -22,7 +22,20 @@ import java.util.SortedMap; -import static com.alibaba.boot.dubbo.util.DubboUtils.*; +import static com.alibaba.boot.dubbo.util.DubboUtils.BASE_PACKAGES_PROPERTY_NAME; +import static com.alibaba.boot.dubbo.util.DubboUtils.DEFAULT_MULTIPLE_CONFIG_PROPERTY_VALUE; +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.DUBBO_GITHUB_URL; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_MAILING_LIST; +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.DUBBO_SPRING_BOOT_GITHUB_URL; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_GIT_URL; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_ISSUES_URL; +import static com.alibaba.boot.dubbo.util.DubboUtils.MULTIPLE_CONFIG_PROPERTY_NAME; +import static com.alibaba.boot.dubbo.util.DubboUtils.OVERRIDE_CONFIG_PROPERTY_NAME; +import static com.alibaba.boot.dubbo.util.DubboUtils.filterDubboProperties; /** * {@link DubboUtils} Test @@ -40,7 +53,7 @@ public void testConstants() { Assert.assertEquals("dubbo.scan", DUBBO_SCAN_PREFIX); - Assert.assertEquals("dubbo.scan.basePackages", BASE_PACKAGES_PROPERTY_NAME); + Assert.assertEquals("dubbo.scan.base-packages", BASE_PACKAGES_PROPERTY_NAME); Assert.assertEquals("dubbo.config", DUBBO_CONFIG_PREFIX); diff --git a/dubbo-spring-boot-parent/pom.xml b/dubbo-spring-boot-parent/pom.xml index b22a36d4b..82ab7009e 100644 --- a/dubbo-spring-boot-parent/pom.xml +++ b/dubbo-spring-boot-parent/pom.xml @@ -37,8 +37,8 @@ 1.8 UTF-8 UTF-8 -2.0.3.RELEASE -2.6.2 +2.1.1.RELEASE +2.6.5 0.2 3.4.9 2.12.0 @@ -57,6 +57,7 @@0.12 2.5.3 2.19.1 +1.0.2 @@ -92,6 +93,13 @@ + + + +com.alibaba.spring +spring-context-support +${alibaba-spring-context-support.version} ++ org.apache.zookeeper @@ -416,6 +424,8 @@**/*.fc **/*.javascript **/*.properties +**/*.yml +**/*.yaml **/*.thrift **/*.sh **/*.bat diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/pom.xml b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/pom.xml index dec0ef069..962dea625 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/pom.xml +++ b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/pom.xml @@ -53,6 +53,11 @@${project.version} + +com.alibaba +dubbo ++ ${project.groupId} dubbo-spring-boot-sample-api diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboConsumerDemo.java b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboConsumerDemo.java index 705101ae5..7f10d51ea 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboConsumerDemo.java +++ b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/bootstrap/DubboConsumerDemo.java @@ -17,8 +17,9 @@ package com.alibaba.boot.dubbo.demo.consumer.bootstrap; import com.alibaba.boot.dubbo.demo.consumer.controller.DemoConsumerController; -import org.springframework.boot.SpringApplication; + import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; /** * Dubbo Consumer Demo @@ -31,9 +32,8 @@ public class DubboConsumerDemo { public static void main(String[] args) { - - SpringApplication.run(DubboConsumerDemo.class,args); - + new SpringApplicationBuilder(DubboConsumerDemo.class) + .profiles("prod") + .run(args); } - } diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/controller/DemoConsumerController.java b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/controller/DemoConsumerController.java index 1897979a4..99cb0fc1b 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/controller/DemoConsumerController.java +++ b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/java/com/alibaba/boot/dubbo/demo/consumer/controller/DemoConsumerController.java @@ -15,8 +15,10 @@ * limitations under the License. */ package com.alibaba.boot.dubbo.demo.consumer.controller; + import com.alibaba.boot.dubbo.demo.consumer.DemoService; import com.alibaba.dubbo.config.annotation.Reference; + import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -31,8 +33,8 @@ @RestController public class DemoConsumerController { - @Reference(version = "${demo.service.version}", - application = "${dubbo.application.id}", + @Reference( + version = "${demo.service.version}", url = "dubbo://localhost:12345") private DemoService demoService; diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.properties b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.properties deleted file mode 100644 index df91988c6..000000000 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.properties +++ /dev/null @@ -1,38 +0,0 @@ -# Spring boot application -spring.application.name = dubbo-consumer-demo -server.port = 8080 -management.server.port = 8081 - -# DemoService service version -demo.service.version = 1.0.0 - -# Dubbo Config properties -## ApplicationConfig Bean -dubbo.application.id = dubbo-consumer-demo -dubbo.application.name = dubbo-consumer-demo - -## Legacy QOS Config -dubbo.qos.port = 22223 - -## ProtocolConfig Bean -dubbo.protocol.id = dubbo -dubbo.protocol.name = dubbo -dubbo.protocol.port = 12345 - -# Dubbo Endpoint (default status is disable) -endpoints.dubbo.enabled = true - -# Dubbo Health -## StatusChecker Name defaults (default : "memory", "load" ) -management.health.dubbo.status.defaults = memory - -# Enables Dubbo All Endpoints -management.endpoint.dubbo.enabled = true -management.endpoint.dubbo-shutdown.enabled = true -management.endpoint.dubbo-configs.enabled = true -management.endpoint.dubbo-services.enabled = true -management.endpoint.dubbo-references.enabled = true -management.endpoint.dubbo-properties.enabled = true - -# Exposes all web endpoints -management.endpoints.web.exposure.include = * \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.yml b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.yml new file mode 100644 index 000000000..9aad95db6 --- /dev/null +++ b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-consumer/src/main/resources/application.yml @@ -0,0 +1,37 @@ +spring: + application: + name: dubbo-consumer-demo + +server: + port: 8080 + +management: + server: + port: 8081 + +dubbo: + application: + id: ${spring.application.name} + logger: slf4j + protocol: + id: dubbo + name: dubbo + port: 12345 + +--- +spring: + profiles: prod + +endpoints: + dubbo: + enabled: true + +management: + health: + dubbo: + status: + defaults: memory + endpoints: + web: + exposure: + include: "*" \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml index 1dc600b53..bb4eff8e7 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml +++ b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/pom.xml @@ -26,7 +26,7 @@4.0.0 dubbo-spring-boot-sample-provider -Dubbo Spring Boot Sample : Provider +Dubbo Spring Boot Sample : Provider @@ -36,6 +36,30 @@ spring-boot-starter + + +org.jboss.resteasy +resteasy-jaxrs +3.0.19.Final ++ + +javax.validation +validation-api +1.1.0.Final ++ +org.mortbay.jetty +jetty +6.1.26 ++ ++ +org.mortbay.jetty +servlet-api ++ org.springframework.boot spring-boot-starter-actuator @@ -53,6 +77,11 @@${project.version} + +com.alibaba +dubbo +${project.groupId} dubbo-spring-boot-sample-api diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java index 48bfc22bf..eda8d4127 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java +++ b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/java/com/alibaba/boot/dubbo/demo/provider/service/DefaultDemoService.java @@ -19,6 +19,10 @@ import com.alibaba.boot.dubbo.demo.consumer.DemoService; import com.alibaba.dubbo.config.annotation.Service; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; + /** * Default {@link DemoService} * @@ -28,14 +32,15 @@ */ @Service( version = "${demo.service.version}", - application = "${dubbo.application.id}", - protocol = "${dubbo.protocol.id}", + protocol = {"dubbo", "rest"}, registry = "${dubbo.registry.id}" ) +@Path("demo") public class DefaultDemoService implements DemoService { - public String sayHello(String name) { + @GET + @Path("/say-hello") + public String sayHello(@QueryParam("name") String name) { return "Hello, " + name + " (from Spring Boot)"; } - } \ No newline at end of file diff --git a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties index 323f72e43..b6f2c3a3e 100644 --- a/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties +++ b/dubbo-spring-boot-samples/dubbo-spring-boot-sample-provider/src/main/resources/application.properties @@ -7,21 +7,25 @@ server.port = 9090 demo.service.version = 1.0.0 # Base packages to scan Dubbo Component: @com.alibaba.dubbo.config.annotation.Service -dubbo.scan.basePackages = com.alibaba.boot.dubbo.demo.provider.service +dubbo.scan.base-packages = com.alibaba.boot.dubbo.demo.provider.service # Dubbo Config properties ## ApplicationConfig Bean -dubbo.application.id = dubbo-provider-demo -dubbo.application.name = dubbo-provider-demo -dubbo.application.qos.port=22222 +dubbo.application.qos.port=0 dubbo.application.qos.enable=true + +## Enable multiple config bindings +dubbo.config.multiple =true + ## ProtocolConfig Bean -dubbo.protocol.id = dubbo -dubbo.protocol.name = dubbo -dubbo.protocol.port = 12345 -dubbo.protocol.status = server +dubbo.protocols.dubbo.name = dubbo +dubbo.protocols.dubbo.port = 12345 +dubbo.protocols.dubbo.status = server + +dubbo.protocols.rest.name = rest +dubbo.protocols.rest.port = 8888 ## RegistryConfig Bean dubbo.registry.id = my-registry @@ -29,11 +33,11 @@ dubbo.registry.address = N/A # Enables Dubbo All Endpoints management.endpoint.dubbo.enabled = true -management.endpoint.dubbo-shutdown.enabled = true -management.endpoint.dubbo-configs.enabled = true -management.endpoint.dubbo-services.enabled = true -management.endpoint.dubbo-references.enabled = true -management.endpoint.dubbo-properties.enabled = true +management.endpoint.dubboShutdown.enabled = true +management.endpoint.dubboConfigs.enabled = true +management.endpoint.dubboServices.enabled = true +management.endpoint.dubboReferences.enabled = true +management.endpoint.dubboProperties.enabled = true # Dubbo Health ## StatusChecker Name defaults (default : "memory", "load" ) diff --git a/dubbo-spring-boot-starter/pom.xml b/dubbo-spring-boot-starter/pom.xml index 993366029..f5e7dafed 100644 --- a/dubbo-spring-boot-starter/pom.xml +++ b/dubbo-spring-boot-starter/pom.xml @@ -36,24 +36,20 @@- - - org.springframework.boot spring-boot-starter -provided -- com.alibaba -dubbo +true org.apache.zookeeper zookeeper +true org.apache.curator curator-framework +true