diff --git a/.travis.yml b/.travis.yml index 5883b8911..71e20320e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,8 @@ language: java sudo: false # faster builds jdk: - - oraclejdk10 - - oraclejdk9 + - openjdk10 + - openjdk9 - oraclejdk8 script: "mvn clean package" diff --git a/README.md b/README.md index 2c4db88c3..1d90f7ad6 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ You can introduce the latest `dubbo-spring-boot-starter` to your project by addi com.alibaba.boot dubbo-spring-boot-starter - 0.2.0 + 0.2.1-SNAPSHOT diff --git a/README_CN.md b/README_CN.md index fb19660d2..bdf584012 100644 --- a/README_CN.md +++ b/README_CN.md @@ -26,7 +26,7 @@ com.alibaba.boot dubbo-spring-boot-starter - 0.2.0 + 0.2.1-SNAPSHOT diff --git a/dubbo-spring-boot-actuator/README.md b/dubbo-spring-boot-actuator/README.md index 103aa7dad..401729256 100644 --- a/dubbo-spring-boot-actuator/README.md +++ b/dubbo-spring-boot-actuator/README.md @@ -33,7 +33,7 @@ You can introduce the latest `dubbo-spring-boot-actuator` to your project by ad com.alibaba.boot dubbo-spring-boot-actuator - 0.2.0 + 0.2.1-SNAPSHOT ``` If your project failed to resolve the dependency, try to add the following repository: @@ -162,11 +162,11 @@ Actuator endpoint `dubbo` supports Actuator Endpoints : | ID | Enabled | HTTP URI | HTTP Method | Description | Content Type | | ------------------- | ----------- | ----------------------------------- | ------------------ | ------------------ | ------------------ | | `dubbo` | `true` | `/actuator/dubbo` | `GET` | Exposes Dubbo's meta data | `application/json` | -| `dubbo-properties` | `true` | `/actuator/dubbo/properties` | `GET` | Exposes all Dubbo's Properties | `application/json` | -| `dubbo-services` | `false` | `/dubbo/services` | `GET` | Exposes all Dubbo's `ServiceBean` | `application/json` | -| `dubbo-references` | `false` | `/actuator/dubbo/references` | `GET` | Exposes all Dubbo's `ReferenceBean` | `application/json` | -| `dubbo-configs` | `true` | `/actuator/dubbo/configs` | `GET` | Exposes all Dubbo's `*Config` | `application/json` | -| `dubbo-shutdown` | `false` | `/actuator/dubbo/shutdown` | `POST` | Shutdown Dubbo services | `application/json` | +| `dubboProperties` | `true` | `/actuator/dubbo/properties` | `GET` | Exposes all Dubbo's Properties | `application/json` | +| `dubboServices` | `false` | `/dubbo/services` | `GET` | Exposes all Dubbo's `ServiceBean` | `application/json` | +| `dubboReferences` | `false` | `/actuator/dubbo/references` | `GET` | Exposes all Dubbo's `ReferenceBean` | `application/json` | +| `dubboConfigs` | `true` | `/actuator/dubbo/configs` | `GET` | Exposes all Dubbo's `*Config` | `application/json` | +| `dubboShutdown` | `false` | `/actuator/dubbo/shutdown` | `POST` | Shutdown Dubbo services | `application/json` | @@ -184,7 +184,7 @@ Actuator endpoint `dubbo` supports Actuator Endpoints : { "timestamp": 1516623290166, "versions": { - "dubbo-spring-boot": "0.2.0" + "dubbo-spring-boot": "0.2.0", "dubbo": "2.6.2" }, "urls": { @@ -503,10 +503,10 @@ Dubbo Spring Boot providers actuator endpoints , however some of them are disabl ```properties # 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 ``` diff --git a/dubbo-spring-boot-actuator/README_CN.md b/dubbo-spring-boot-actuator/README_CN.md index 395e3efcb..54db9ccc8 100644 --- a/dubbo-spring-boot-actuator/README_CN.md +++ b/dubbo-spring-boot-actuator/README_CN.md @@ -31,14 +31,14 @@ com.alibaba.boot dubbo-spring-boot-starter - 0.2.0 + 0.2.1-SNAPSHOT com.alibaba.boot dubbo-spring-boot-actuator - 0.2.0 + 0.2.1-SNAPSHOT ... diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboEndpointsAutoConfiguration.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboEndpointsAutoConfiguration.java index 038e0bf51..efa5b4153 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboEndpointsAutoConfiguration.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboEndpointsAutoConfiguration.java @@ -16,7 +16,13 @@ */ package com.alibaba.boot.dubbo.actuate.autoconfigure; -import com.alibaba.boot.dubbo.actuate.endpoint.*; +import com.alibaba.boot.dubbo.actuate.endpoint.DubboConfigsMetadataEndpoint; +import com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpoint; +import com.alibaba.boot.dubbo.actuate.endpoint.DubboPropertiesEndpoint; +import com.alibaba.boot.dubbo.actuate.endpoint.DubboReferencesMetadataEndpoint; +import com.alibaba.boot.dubbo.actuate.endpoint.DubboServicesMetadataEndpoint; +import com.alibaba.boot.dubbo.actuate.endpoint.DubboShutdownEndpoint; + import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnEnabledEndpoint; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; @@ -27,7 +33,7 @@ /** * Dubbo {@link Endpoint} Auto-{@link Configuration} * - * @author Mercy + * * @see Endpoint * @see Configuration * @since 0.2.0 diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboHealthIndicatorAutoConfiguration.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboHealthIndicatorAutoConfiguration.java index c53c958df..20d2cf1ff 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboHealthIndicatorAutoConfiguration.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/autoconfigure/DubboHealthIndicatorAutoConfiguration.java @@ -19,6 +19,7 @@ import com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicator; import com.alibaba.boot.dubbo.actuate.health.DubboHealthIndicatorProperties; import com.alibaba.boot.dubbo.autoconfigure.DubboAutoConfiguration; + import org.springframework.boot.actuate.autoconfigure.endpoint.EndpointAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator; import org.springframework.boot.actuate.health.HealthIndicator; @@ -33,7 +34,7 @@ /** * Dubbo {@link DubboHealthIndicator} Auto Configuration * - * @author Mercy + * * @see HealthIndicator * @since 1.0.0 */ diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/AbstractDubboEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/AbstractDubboEndpoint.java index 95b865589..45a0cba56 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/AbstractDubboEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/AbstractDubboEndpoint.java @@ -19,6 +19,7 @@ import com.alibaba.dubbo.config.ProtocolConfig; import com.alibaba.dubbo.config.spring.ServiceBean; import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; + import org.springframework.beans.BeansException; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.context.ApplicationContext; @@ -45,7 +46,7 @@ /** * Abstract Dubbo {@link Endpoint @Endpoint} * - * @author Mercy + * * @since 0.2.0 */ public abstract class AbstractDubboEndpoint implements ApplicationContextAware, EnvironmentAware { diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboConfigsMetadataEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboConfigsMetadataEndpoint.java index b5ae637e8..4cdcc2e33 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboConfigsMetadataEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboConfigsMetadataEndpoint.java @@ -16,7 +16,18 @@ */ package com.alibaba.boot.dubbo.actuate.endpoint; -import com.alibaba.dubbo.config.*; +import com.alibaba.dubbo.config.AbstractConfig; +import com.alibaba.dubbo.config.ApplicationConfig; +import com.alibaba.dubbo.config.ConsumerConfig; +import com.alibaba.dubbo.config.MethodConfig; +import com.alibaba.dubbo.config.ModuleConfig; +import com.alibaba.dubbo.config.MonitorConfig; +import com.alibaba.dubbo.config.ProtocolConfig; +import com.alibaba.dubbo.config.ProviderConfig; +import com.alibaba.dubbo.config.ReferenceConfig; +import com.alibaba.dubbo.config.RegistryConfig; +import com.alibaba.dubbo.config.ServiceConfig; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; @@ -29,10 +40,10 @@ /** * Dubbo Configs Metadata {@link Endpoint} * - * @author Mercy + * * @since 0.2.0 */ -@Endpoint(id = "dubbo-configs") +@Endpoint(id = "dubboConfigs") public class DubboConfigsMetadataEndpoint extends AbstractDubboEndpoint { @ReadOperation diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpoint.java index d5d503f07..eba7b5666 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboEndpoint.java @@ -18,37 +18,29 @@ import com.alibaba.boot.dubbo.util.DubboUtils; import com.alibaba.dubbo.common.Version; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; import java.util.LinkedHashMap; import java.util.Map; -import static com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpoint.DUBBO_ENDPOINT_ID; -import static com.alibaba.boot.dubbo.util.DubboUtils.*; +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.DUBBO_SPRING_BOOT_GIT_URL; +import static com.alibaba.boot.dubbo.util.DubboUtils.DUBBO_SPRING_BOOT_ISSUES_URL; /** * Actuator {@link Endpoint} to expose Dubbo Meta Data * - * @author Mercy + * * @see Endpoint * @since 1.0.0 */ -@Endpoint(id = DUBBO_ENDPOINT_ID) +@Endpoint(id = "dubbo") public class DubboEndpoint { - public static final String DUBBO_ENDPOINT_ID = "dubbo"; - - public static final String DUBBO_SHUTDOWN_ENDPOINT_ID = DUBBO_ENDPOINT_ID + "-shutdown"; - - public static final String DUBBO_CONFIGS_ENDPOINT_ID = DUBBO_ENDPOINT_ID + "-configs"; - - public static final String DUBBO_SERVICES_ENDPOINT_ID = DUBBO_ENDPOINT_ID + "-services"; - - public static final String DUBBO_REFERENCES_ENDPOINT_ID = DUBBO_ENDPOINT_ID + "-references"; - - public static final String DUBBO_PROPERTIES_ENDPOINT_ID = DUBBO_ENDPOINT_ID + "-properties"; - @ReadOperation public Map invoke() { diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboPropertiesEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboPropertiesEndpoint.java index eeec4c9d6..be302b6ad 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboPropertiesEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboPropertiesEndpoint.java @@ -21,16 +21,15 @@ import java.util.SortedMap; -import static com.alibaba.boot.dubbo.actuate.endpoint.DubboEndpoint.DUBBO_PROPERTIES_ENDPOINT_ID; import static com.alibaba.boot.dubbo.util.DubboUtils.filterDubboProperties; /** * Dubbo Properties {@link Endpoint} * - * @author Mercy + * * @since 1.0.0 */ -@Endpoint(id = DUBBO_PROPERTIES_ENDPOINT_ID) +@Endpoint(id = "dubboProperties") public class DubboPropertiesEndpoint extends AbstractDubboEndpoint { @ReadOperation diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboReferencesMetadataEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboReferencesMetadataEndpoint.java index 649b06614..29da19bef 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboReferencesMetadataEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboReferencesMetadataEndpoint.java @@ -19,6 +19,7 @@ import com.alibaba.dubbo.config.annotation.Reference; import com.alibaba.dubbo.config.spring.ReferenceBean; import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; + import org.springframework.beans.factory.annotation.InjectionMetadata; import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; @@ -29,10 +30,10 @@ /** * Dubbo {@link Reference} Metadata {@link Endpoint} * - * @author Mercy + * * @since 1.0.0 */ -@Endpoint(id = "dubbo-references") +@Endpoint(id = "dubboReferences") public class DubboReferencesMetadataEndpoint extends AbstractDubboEndpoint { @ReadOperation diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboServicesMetadataEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboServicesMetadataEndpoint.java index 4b36484d8..46582392e 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboServicesMetadataEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboServicesMetadataEndpoint.java @@ -18,6 +18,7 @@ import com.alibaba.dubbo.config.annotation.Service; import com.alibaba.dubbo.config.spring.ServiceBean; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; @@ -27,10 +28,10 @@ /** * Dubbo {@link Service} Metadata {@link Endpoint} * - * @author Mercy + * * @since 0.2.0 */ -@Endpoint(id = "dubbo-services") +@Endpoint(id = "dubboServices") public class DubboServicesMetadataEndpoint extends AbstractDubboEndpoint { @ReadOperation diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboShutdownEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboShutdownEndpoint.java index 9ad9e833f..151663f3f 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboShutdownEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/endpoint/DubboShutdownEndpoint.java @@ -19,6 +19,7 @@ import com.alibaba.dubbo.config.ProtocolConfig; import com.alibaba.dubbo.config.spring.ServiceBean; import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; + import org.springframework.boot.actuate.endpoint.annotation.Endpoint; import org.springframework.boot.actuate.endpoint.annotation.WriteOperation; @@ -31,10 +32,10 @@ /** * Dubbo Shutdown * - * @author Mercy + * * @since 0.2.0 */ -@Endpoint(id = "dubbo-shutdown") +@Endpoint(id = "dubboShutdown") public class DubboShutdownEndpoint extends AbstractDubboEndpoint { diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicator.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicator.java index 4de90222f..e84a24e98 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicator.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicator.java @@ -20,6 +20,7 @@ import com.alibaba.dubbo.common.status.StatusChecker; import com.alibaba.dubbo.config.ProtocolConfig; import com.alibaba.dubbo.config.ProviderConfig; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.health.AbstractHealthIndicator; import org.springframework.boot.actuate.health.Health; @@ -37,7 +38,7 @@ /** * Dubbo {@link HealthIndicator} * - * @author Mercy + * * @see HealthIndicator * @since 1.0.0 */ diff --git a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorProperties.java b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorProperties.java index bd35ed996..e6db92811 100644 --- a/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorProperties.java +++ b/dubbo-spring-boot-actuator/src/main/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorProperties.java @@ -17,6 +17,7 @@ package com.alibaba.boot.dubbo.actuate.health; import com.alibaba.dubbo.common.status.StatusChecker; + import org.springframework.boot.actuate.health.HealthIndicator; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -29,7 +30,7 @@ /** * Dubbo {@link HealthIndicator} Properties * - * @author Mercy + * * @see HealthIndicator * @since 1.0.0 */ @@ -53,7 +54,6 @@ public void setStatus(Status status) { /** * The nested class for {@link StatusChecker}'s names - *

*

      * 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..ac2b04936 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;
@@ -32,7 +32,7 @@
 /**
  * {@link DubboEndpoint} Test
  *
- * @author Mercy
+ *
  * @see DubboEndpoint
  * @since 1.0.0
  */
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..d01e67cdf 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;
@@ -32,7 +33,7 @@
 /**
  * {@link DubboEndpointsAutoConfiguration} Test
  *
- * @author Mercy
+ *
  * @since 0.2.0
  */
 @RunWith(SpringRunner.class)
@@ -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());
 
-        Map demoServiceMeta = 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-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorTest.java b/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorTest.java
index 6d736f01b..41de0a8e1 100644
--- a/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorTest.java
+++ b/dubbo-spring-boot-actuator/src/test/java/com/alibaba/boot/dubbo/actuate/health/DubboHealthIndicatorTest.java
@@ -17,6 +17,7 @@
 package com.alibaba.boot.dubbo.actuate.health;
 
 import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig;
+
 import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -33,7 +34,7 @@
 /**
  * {@link DubboHealthIndicator} Test
  *
- * @author Mercy
+ *
  * @see DubboHealthIndicator
  * @since 1.0.0
  */
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
 
     com.alibaba.boot
     dubbo-spring-boot-autoconfigure
-    0.2.0
+    0.2.1-SNAPSHOT
 
 ```
 
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 @@
             spring-boot-autoconfigure
             true
         
+
         
             org.springframework.boot
             spring-boot-starter-logging
@@ -58,11 +59,18 @@
             true
         
 
+        
+        
+            com.alibaba.spring
+            spring-context-support
+        
+
         
         
             org.springframework.boot
             spring-boot-starter-test
             test
         
+
     
 
\ No newline at end of file
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 486c1b917..58029f446 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
@@ -26,6 +26,7 @@
 import com.alibaba.dubbo.config.spring.context.annotation.DubboConfigConfiguration;
 import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
 import com.alibaba.dubbo.config.spring.context.annotation.EnableDubboConfig;
+
 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@@ -38,14 +39,15 @@
 
 import java.util.Set;
 
-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.DUBBO_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;
 
 /**
  * Dubbo Auto {@link Configuration}
  *
- * @author Mercy
  * @see ApplicationConfig
  * @see Service
  * @see Reference
@@ -59,27 +61,6 @@
 @ConditionalOnClass(AbstractConfig.class)
 public class DubboAutoConfiguration {
 
-    /**
-     * Single Dubbo Config Configuration
-     *
-     * @see EnableDubboConfig
-     * @see DubboConfigConfiguration.Single
-     */
-    @EnableDubboConfig
-    protected static class SingleDubboConfigConfiguration {
-    }
-
-    /**
-     * Multiple Dubbo Config Configuration , equals @EnableDubboConfig.multiple() == true
-     *
-     * @see EnableDubboConfig
-     * @see DubboConfigConfiguration.Multiple
-     */
-    @ConditionalOnProperty(name = MULTIPLE_CONFIG_PROPERTY_NAME, havingValue = "true")
-    @EnableDubboConfig(multiple = true)
-    protected static class MultipleDubboConfigConfiguration {
-    }
-
     /**
      * Creates {@link ServiceAnnotationBeanPostProcessor} Bean
      *
@@ -112,4 +93,25 @@ public ReferenceAnnotationBeanPostProcessor referenceAnnotationBeanPostProcessor
         return new ReferenceAnnotationBeanPostProcessor();
     }
 
+    /**
+     * Single Dubbo Config Configuration
+     *
+     * @see EnableDubboConfig
+     * @see DubboConfigConfiguration.Single
+     */
+    @EnableDubboConfig
+    protected static class SingleDubboConfigConfiguration {
+    }
+
+    /**
+     * Multiple Dubbo Config Configuration , equals @EnableDubboConfig.multiple() == true
+     *
+     * @see EnableDubboConfig
+     * @see DubboConfigConfiguration.Multiple
+     */
+    @ConditionalOnProperty(name = MULTIPLE_CONFIG_PROPERTY_NAME, havingValue = "true")
+    @EnableDubboConfig(multiple = true)
+    protected static class MultipleDubboConfigConfiguration {
+    }
+
 }
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..72a66e7c1 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;
 
@@ -33,7 +36,6 @@
  * Spring Boot Relaxed {@link DubboConfigBinder} implementation
  * see org.springframework.boot.context.properties.ConfigurationPropertiesBinder
  *
- * @author Mercy
  * @since 0.1.1
  */
 public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder {
@@ -41,13 +43,15 @@ public class RelaxedDubboConfigBinder extends AbstractDubboConfigBinder {
     @Override
     public  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/AwaitingNonWebApplicationListener.java b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListener.java
index 55c3daa0b..b8a22348e 100644
--- a/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListener.java
+++ b/dubbo-spring-boot-autoconfigure/src/main/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListener.java
@@ -21,30 +21,68 @@
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.WebApplicationType;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.ApplicationEvent;
 import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextClosedEvent;
+import org.springframework.context.event.SmartApplicationListener;
+import org.springframework.util.ObjectUtils;
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 /**
  * Awaiting Non-Web Spring Boot {@link ApplicationListener}
  *
- * @author Mercy
  * @since 0.1.1
  */
-public class AwaitingNonWebApplicationListener implements ApplicationListener {
+public class AwaitingNonWebApplicationListener implements SmartApplicationListener {
 
     private static final Logger logger = LoggerFactory.getLogger(AwaitingNonWebApplicationListener.class);
 
-    private static final ExecutorService executorService = Executors.newSingleThreadExecutor();
-
-    private static final AtomicBoolean shutdownHookRegistered = new AtomicBoolean(false);
+    private static final Class[] SUPPORTED_APPLICATION_EVENTS =
+            of(ApplicationReadyEvent.class, ContextClosedEvent.class);
 
     private static final AtomicBoolean awaited = new AtomicBoolean(false);
 
+    private final Lock lock = new ReentrantLock();
+
+    private final Condition condition = lock.newCondition();
+
+    private final ExecutorService executorService = Executors.newSingleThreadExecutor();
+
+    @Override
+    public boolean supportsEventType(Class eventType) {
+        return ObjectUtils.containsElement(SUPPORTED_APPLICATION_EVENTS, eventType);
+    }
+
     @Override
-    public void onApplicationEvent(ApplicationReadyEvent event) {
+    public boolean supportsSourceType(Class sourceType) {
+        return true;
+    }
+
+    private static  T[] of(T... values) {
+        return values;
+    }
+
+    @Override
+    public void onApplicationEvent(ApplicationEvent event) {
+        if (event instanceof ApplicationReadyEvent) {
+            onApplicationReadyEvent((ApplicationReadyEvent) event);
+        } else if (event instanceof ContextClosedEvent) {
+            onContextClosedEvent((ContextClosedEvent) event);
+        }
+    }
+
+    @Override
+    public int getOrder() {
+        return LOWEST_PRECEDENCE;
+    }
+
+    protected void onApplicationReadyEvent(ApplicationReadyEvent event) {
 
         final SpringApplication springApplication = event.getSpringApplication();
 
@@ -52,46 +90,64 @@ public void onApplicationEvent(ApplicationReadyEvent event) {
             return;
         }
 
-        executorService.execute(new Runnable() {
-            @Override
-            public void run() {
-
-                synchronized (springApplication) {
-                    if (logger.isInfoEnabled()) {
-                        logger.info(" [Dubbo] Current Spring Boot Application is await...");
-                    }
-                    while (!awaited.get()) {
-                        try {
-                            springApplication.wait();
-                        } catch (InterruptedException e) {
-                            Thread.currentThread().interrupt();
-                        }
-                    }
+        await();
+
+    }
+
+    protected void onContextClosedEvent(ContextClosedEvent event) {
+        release();
+        shutdown();
+    }
+
+    protected void await() {
+
+        // has been waited, return immediately
+        if (awaited.get()) {
+            return;
+        }
+
+        executorService.execute(() -> executeMutually(() -> {
+            while (!awaited.get()) {
+                if (logger.isInfoEnabled()) {
+                    logger.info(" [Dubbo] Current Spring Boot Application is await...");
+                }
+                try {
+                    condition.await();
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
                 }
             }
-        });
+        }));
+    }
 
-        // register ShutdownHook
-        if (shutdownHookRegistered.compareAndSet(false, true)) {
-            registerShutdownHook(new Thread(new Runnable() {
-                @Override
-                public void run() {
-                    synchronized (springApplication) {
-                        if (awaited.compareAndSet(false, true)) {
-                            springApplication.notifyAll();
-                            if (logger.isInfoEnabled()) {
-                                logger.info(" [Dubbo] Current Spring Boot Application is about to shutdown...");
-                            }
-                            // Shutdown executorService
-                            executorService.shutdown();
-                        }
-                    }
+    protected void release() {
+        executeMutually(() -> {
+            while (awaited.compareAndSet(false, true)) {
+                if (logger.isInfoEnabled()) {
+                    logger.info(" [Dubbo] Current Spring Boot Application is about to shutdown...");
                 }
-            }));
+                condition.signalAll();
+            }
+        });
+    }
+
+    private void shutdown() {
+        if (!executorService.isShutdown()) {
+            // Shutdown executorService
+            executorService.shutdown();
+        }
+    }
+
+    private void executeMutually(Runnable runnable) {
+        try {
+            lock.lock();
+            runnable.run();
+        } finally {
+            lock.unlock();
         }
     }
 
-    private void registerShutdownHook(Thread thread) {
-        Runtime.getRuntime().addShutdownHook(thread);
+    static AtomicBoolean getAwaited() {
+        return awaited;
     }
 }
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 33ac29b3c..e2a236318 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
@@ -18,6 +18,7 @@
 
 import com.alibaba.dubbo.common.utils.ConfigUtils;
 import com.alibaba.dubbo.config.AbstractConfig;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
@@ -28,7 +29,9 @@
 
 import java.util.SortedMap;
 
-import static com.alibaba.boot.dubbo.util.DubboUtils.*;
+import static com.alibaba.boot.dubbo.util.DubboUtils.DEFAULT_OVERRIDE_CONFIG_PROPERTY_VALUE;
+import static com.alibaba.boot.dubbo.util.DubboUtils.OVERRIDE_CONFIG_PROPERTY_NAME;
+import static com.alibaba.boot.dubbo.util.DubboUtils.filterDubboProperties;
 
 /**
  * {@link ApplicationListener} to override the dubbo properties from {@link Environment}into
@@ -36,7 +39,6 @@
  * {@link AbstractConfig Dubbo Config} on {@link ApplicationEnvironmentPreparedEvent}.
  * 

* - * @author Mercy * @see ConfigUtils * @since 1.0.0 */ 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..9802a3b96 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,23 +25,32 @@ 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} * - * @author Mercy * @see ApplicationListener * @since 1.0.0 */ @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 +65,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 +82,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..76ee68963 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,16 +16,16 @@ */ 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 * - * @author Mercy * @since 1.0.0 */ public abstract class DubboUtils { @@ -61,7 +61,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 @@ -129,7 +129,7 @@ public static SortedMap filterDubboProperties(ConfigurableEnviro String propertyName = entry.getKey(); if (propertyName.startsWith(DUBBO_PREFIX + PROPERTY_NAME_SEPARATOR) - && entry.getValue() != null) { + && entry.getValue() != null) { dubboProperties.put(propertyName, entry.getValue().toString()); } 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 9349d8129..9b20c58f8 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 @@ -16,7 +16,12 @@ */ package com.alibaba.boot.dubbo.util; -import org.springframework.core.env.*; +import org.springframework.core.env.CompositePropertySource; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.Environment; +import org.springframework.core.env.MutablePropertySources; +import org.springframework.core.env.PropertySource; import org.springframework.util.ObjectUtils; import java.util.Collections; @@ -26,7 +31,6 @@ /** * The utilities class for {@link Environment} * - * @author Mercy * @see Environment * @since 1.0.0 */ 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/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java index ee9350938..af38587b8 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnMultipleConfigTest.java @@ -16,10 +16,15 @@ */ package com.alibaba.boot.dubbo.autoconfigure; -import com.alibaba.dubbo.config.*; +import com.alibaba.dubbo.config.ApplicationConfig; +import com.alibaba.dubbo.config.ConsumerConfig; +import com.alibaba.dubbo.config.ModuleConfig; +import com.alibaba.dubbo.config.MonitorConfig; +import com.alibaba.dubbo.config.ProtocolConfig; +import com.alibaba.dubbo.config.ProviderConfig; +import com.alibaba.dubbo.config.RegistryConfig; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -38,7 +43,7 @@ /** * {@link DubboAutoConfiguration} Test On multiple Dubbo Configuration * - * @author Mercy + * * @since 1.0.0 */ @RunWith(SpringJUnit4ClassRunner.class) diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java index c8092d3f6..b60340e75 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/DubboAutoConfigurationOnSingleConfigTest.java @@ -16,9 +16,16 @@ */ package com.alibaba.boot.dubbo.autoconfigure; -import com.alibaba.dubbo.config.*; +import com.alibaba.dubbo.config.ApplicationConfig; +import com.alibaba.dubbo.config.ConsumerConfig; +import com.alibaba.dubbo.config.ModuleConfig; +import com.alibaba.dubbo.config.MonitorConfig; +import com.alibaba.dubbo.config.ProtocolConfig; +import com.alibaba.dubbo.config.ProviderConfig; +import com.alibaba.dubbo.config.RegistryConfig; import com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; import com.alibaba.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,7 +39,7 @@ /** * {@link DubboAutoConfiguration} Test On single Dubbo Configuration * - * @author Mercy + * * @since 1.0.0 */ @RunWith(SpringJUnit4ClassRunner.class) diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinderTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinderTest.java index 8e080861c..0a151bab8 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinderTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/autoconfigure/RelaxedDubboConfigBinderTest.java @@ -19,6 +19,7 @@ import com.alibaba.dubbo.config.ApplicationConfig; import com.alibaba.dubbo.config.ProtocolConfig; import com.alibaba.dubbo.config.RegistryConfig; + import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,7 +31,7 @@ /** * {@link RelaxedDubboConfigBinder} Test * - * @author Mercy + * * @since 0.1.1 */ @RunWith(SpringJUnit4ClassRunner.class) diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListenerTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListenerTest.java new file mode 100644 index 000000000..42710cd31 --- /dev/null +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/AwaitingNonWebApplicationListenerTest.java @@ -0,0 +1,57 @@ +/* + * 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.context.event; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.builder.SpringApplicationBuilder; + +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * {@link AwaitingNonWebApplicationListener} Test + */ +public class AwaitingNonWebApplicationListenerTest { + + @Test + public void init() { + AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); + awaited.set(false); + + } + + @Test + public void testSingleContextNonWebApplication() { + new SpringApplicationBuilder(Object.class) + .web(WebApplicationType.NONE) + .run().close(); + AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); + Assert.assertTrue(awaited.get()); + } + + @Test + public void testMultipleContextNonWebApplication() { + new SpringApplicationBuilder(Object.class) + .parent(Object.class) + .web(WebApplicationType.NONE) + .run().close(); + AtomicBoolean awaited = AwaitingNonWebApplicationListener.getAwaited(); + Assert.assertTrue(awaited.get()); + } + +} diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerDisableTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerDisableTest.java index c425b8312..c69e5f513 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerDisableTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerDisableTest.java @@ -17,6 +17,7 @@ package com.alibaba.boot.dubbo.context.event; import com.alibaba.dubbo.common.utils.ConfigUtils; + import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -30,7 +31,7 @@ /** * {@link OverrideDubboConfigApplicationListener} Test * - * @author Mercy + * * @see OverrideDubboConfigApplicationListener * @since 1.0.0 */ diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerTest.java index c7d98d0f7..2fd7cd15f 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/OverrideDubboConfigApplicationListenerTest.java @@ -17,6 +17,7 @@ package com.alibaba.boot.dubbo.context.event; import com.alibaba.dubbo.common.utils.ConfigUtils; + import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -30,7 +31,7 @@ /** * {@link OverrideDubboConfigApplicationListener} Test * - * @author Mercy + * * @see OverrideDubboConfigApplicationListener * @since 1.0.0 */ diff --git a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListenerTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListenerTest.java index b603264d2..34bb97196 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListenerTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/context/event/WelcomeLogoApplicationListenerTest.java @@ -26,7 +26,7 @@ /** * {@link WelcomeLogoApplicationListener} Test * - * @author Mercy + * * @see WelcomeLogoApplicationListener * @since 1.0.0 */ 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..066cce5a2 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,12 +22,25 @@ 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 * - * @author Mercy + * * @see DubboUtils * @since 1.0.0 */ @@ -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-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/EnvironmentUtilsTest.java b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/EnvironmentUtilsTest.java index d22ba4983..9155471a3 100644 --- a/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/EnvironmentUtilsTest.java +++ b/dubbo-spring-boot-autoconfigure/src/test/java/com/alibaba/boot/dubbo/util/EnvironmentUtilsTest.java @@ -29,7 +29,7 @@ /** * {@link EnvironmentUtils} Test * - * @author Mercy + * * @see EnvironmentUtils * @since 1.0.0 */ 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