From 0f1fe4c3d58c5c43b1cca83d058368924b5de0db Mon Sep 17 00:00:00 2001 From: mercyblitz Date: Tue, 26 May 2020 15:59:09 +0800 Subject: [PATCH 1/4] Polish apache/dubbo-spring-boot-project#718 : [Samples] Introducing the samples deployed the external Servlet container --- README.md | 2 +- README_CN.md | 2 +- dubbo-spring-boot-actuator/README.md | 26 ++--- ...bboAutoConfigurationConsumerBootstrap.java | 4 +- ...bboAutoConfigurationProviderBootstrap.java | 4 +- .../provider/service/DefaultDemoService.java | 4 +- .../src/main/resources/application.properties | 2 +- ...nalizedConfigurationConsumerBootstrap.java | 4 +- ...nalizedConfigurationProviderBootstrap.java | 5 +- .../provider/service/DefaultDemoService.java | 4 +- .../src/main/resources/application.properties | 2 +- dubbo-spring-boot-samples/pom.xml | 2 + .../DubboRegistryNacosConsumerBootstrap.java | 4 +- .../DubboRegistryNacosProviderBootstrap.java | 4 +- .../provider/service/DefaultDemoService.java | 4 +- .../src/main/resources/application.properties | 2 +- ...bboRegistryZooKeeperConsumerBootstrap.java | 4 +- ...bboRegistryZooKeeperProviderBootstrap.java | 4 +- .../provider/service/DefaultDemoService.java | 4 +- .../src/main/resources/application.properties | 2 +- dubbo-spring-boot-samples/sample-api/pom.xml | 1 + .../consumer/DemoService.java | 2 +- ...ServiceIntrospectionConsumerBootstrap.java | 2 +- .../provider/service/DefaultDemoService.java | 2 +- ...ServiceIntrospectionConsumerBootstrap.java | 2 +- .../provider/service/DefaultDemoService.java | 2 +- .../consumer-sample/pom.xml | 99 +++++++++++++++++++ ...ubboServletContainerConsumerBootstrap.java | 55 +++++++++++ .../src/main/resources/application.yml | 8 ++ .../servlet-container-samples/pom.xml | 35 +++++++ .../provider-sample/pom.xml | 99 +++++++++++++++++++ ...ubboServletContainerProviderBootstrap.java | 60 +++++++++++ .../provider/service/DefaultDemoService.java | 43 ++++++++ .../src/main/resources/application.properties | 16 +++ 34 files changed, 467 insertions(+), 48 deletions(-) rename dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java (93%) rename dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java (90%) rename dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/provider/service/DefaultDemoService.java (93%) rename dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java (94%) rename dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java (90%) rename dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/provider/service/DefaultDemoService.java (91%) rename dubbo-spring-boot-samples/registry-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java (92%) rename dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java (89%) rename dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/provider/service/DefaultDemoService.java (91%) rename dubbo-spring-boot-samples/registry-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java (93%) rename dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java (89%) rename dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/provider/service/DefaultDemoService.java (91%) rename dubbo-spring-boot-samples/sample-api/src/main/java/org/apache/dubbo/spring/boot/{demo => sample}/consumer/DemoService.java (94%) create mode 100644 dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/pom.xml create mode 100644 dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboServletContainerConsumerBootstrap.java create mode 100644 dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/src/main/resources/application.yml create mode 100644 dubbo-spring-boot-samples/servlet-container-samples/pom.xml create mode 100644 dubbo-spring-boot-samples/servlet-container-samples/provider-sample/pom.xml create mode 100644 dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboServletContainerProviderBootstrap.java create mode 100644 dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java create mode 100644 dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/resources/application.properties diff --git a/README.md b/README.md index ec3f472ec..34ac41718 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ public interface DemoService { # Spring boot application spring.application.name=dubbo-auto-configuration-provider-demo # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service - dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service + dubbo.scan.base-packages=org.apache.dubbo.spring.boot.sample.provider.service # Dubbo Application ## The default value of dubbo.application.name is ${spring.application.name} diff --git a/README_CN.md b/README_CN.md index 63fafab8c..8d7b3ebc5 100644 --- a/README_CN.md +++ b/README_CN.md @@ -177,7 +177,7 @@ public interface DemoService { # Spring boot application spring.application.name=dubbo-auto-configuration-provider-demo # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service - dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service + dubbo.scan.base-packages=org.apache.dubbo.spring.boot.sample.provider.service # Dubbo Application ## The default value of dubbo.application.name is ${spring.application.name} diff --git a/dubbo-spring-boot-actuator/README.md b/dubbo-spring-boot-actuator/README.md index 754820afd..b501b9c3f 100644 --- a/dubbo-spring-boot-actuator/README.md +++ b/dubbo-spring-boot-actuator/README.md @@ -201,7 +201,7 @@ Actuator endpoint `dubbo` supports Actuator Endpoints : "dubbo.protocol.port": "12345", "dubbo.registry.address": "N/A", "dubbo.registry.id": "my-registry", - "dubbo.scan.basePackages": "org.apache.dubbo.spring.boot.demo.provider.service" + "dubbo.scan.basePackages": "org.apache.dubbo.spring.boot.sample.provider.service" } ``` @@ -217,7 +217,7 @@ The structure of JSON is simple Key-Value format , the key is property name as a ```json { - "ServiceBean@org.apache.dubbo.spring.boot.demo.api.DemoService#defaultDemoService": { + "ServiceBean@org.apache.dubbo.spring.boot.sample.api.DemoService#defaultDemoService": { "accesslog": null, "actives": null, "cache": null, @@ -233,9 +233,9 @@ The structure of JSON is simple Key-Value format , the key is property name as a "filter": "", "generic": "false", "group": null, - "id": "org.apache.dubbo.spring.boot.demo.api.DemoService", - "interface": "org.apache.dubbo.spring.boot.demo.api.DemoService", - "interfaceClass": "org.apache.dubbo.spring.boot.demo.api.DemoService", + "id": "org.apache.dubbo.spring.boot.sample.api.DemoService", + "interface": "org.apache.dubbo.spring.boot.sample.api.DemoService", + "interfaceClass": "org.apache.dubbo.spring.boot.sample.api.DemoService", "layer": null, "listener": "", "loadbalance": null, @@ -245,7 +245,7 @@ The structure of JSON is simple Key-Value format , the key is property name as a "onconnect": null, "ondisconnect": null, "owner": null, - "path": "org.apache.dubbo.spring.boot.demo.api.DemoService", + "path": "org.apache.dubbo.spring.boot.sample.api.DemoService", "proxy": null, "retries": null, "scope": null, @@ -254,7 +254,7 @@ The structure of JSON is simple Key-Value format , the key is property name as a "timeout": null, "token": null, "unexported": false, - "uniqueServiceName": "org.apache.dubbo.spring.boot.demo.api.DemoService:1.0.0", + "uniqueServiceName": "org.apache.dubbo.spring.boot.sample.api.DemoService:1.0.0", "validation": null, "version": "1.0.0", "warmup": null, @@ -274,7 +274,7 @@ The key is the Bean name of `ServiceBean` , `ServiceBean`'s properties compose v ```json { - "private org.apache.dubbo.spring.boot.demo.api.DemoService org.apache.dubbo.spring.boot.demo.consumer.controller.DemoConsumerController.demoService": { + "private org.apache.dubbo.spring.boot.sample.api.DemoService org.apache.dubbo.spring.boot.sample.consumer.controller.DemoConsumerController.demoService": { "actives": null, "cache": null, "callbacks": null, @@ -285,9 +285,9 @@ The key is the Bean name of `ServiceBean` , `ServiceBean`'s properties compose v "filter": "", "generic": null, "group": null, - "id": "org.apache.dubbo.spring.boot.demo.api.DemoService", - "interface": "org.apache.dubbo.spring.boot.demo.api.DemoService", - "interfaceClass": "org.apache.dubbo.spring.boot.demo.api.DemoService", + "id": "org.apache.dubbo.spring.boot.sample.api.DemoService", + "interface": "org.apache.dubbo.spring.boot.sample.api.DemoService", + "interfaceClass": "org.apache.dubbo.spring.boot.sample.api.DemoService", "layer": null, "lazy": null, "listener": "", @@ -295,7 +295,7 @@ The key is the Bean name of `ServiceBean` , `ServiceBean`'s properties compose v "local": null, "merger": null, "mock": null, - "objectType": "org.apache.dubbo.spring.boot.demo.api.DemoService", + "objectType": "org.apache.dubbo.spring.boot.sample.api.DemoService", "onconnect": null, "ondisconnect": null, "owner": null, @@ -310,7 +310,7 @@ The key is the Bean name of `ServiceBean` , `ServiceBean`'s properties compose v "stub": null, "stubevent": null, "timeout": null, - "uniqueServiceName": "org.apache.dubbo.spring.boot.demo.api.DemoService:1.0.0", + "uniqueServiceName": "org.apache.dubbo.spring.boot.sample.api.DemoService:1.0.0", "url": "dubbo://localhost:12345", "validation": null, "version": "1.0.0", diff --git a/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java b/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java similarity index 93% rename from dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java rename to dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java index 91d731576..b61900fe5 100644 --- a/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java +++ b/dubbo-spring-boot-samples/auto-configure-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboAutoConfigurationConsumerBootstrap.java @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.consumer.bootstrap; +package org.apache.dubbo.spring.boot.sample.consumer.bootstrap; import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.Method; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java similarity index 90% rename from dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java rename to dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java index 265208c93..0c2c23927 100644 --- a/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java +++ b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboAutoConfigurationProviderBootstrap.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.provider.bootstrap; +package org.apache.dubbo.spring.boot.sample.provider.bootstrap; -import org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService; +import org.apache.dubbo.spring.boot.sample.provider.service.DefaultDemoService; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; diff --git a/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java similarity index 93% rename from dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java rename to dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java index eab0793ca..75b1c378b 100644 --- a/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java +++ b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.provider.service; +package org.apache.dubbo.spring.boot.sample.provider.service; import org.apache.dubbo.config.annotation.DubboService; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties index b3de3d9c1..db9e2dbf9 100644 --- a/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties +++ b/dubbo-spring-boot-samples/auto-configure-samples/provider-sample/src/main/resources/application.properties @@ -1,7 +1,7 @@ # Spring boot application spring.application.name=dubbo-auto-configuration-provider-demo # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service -dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service +dubbo.scan.base-packages=org.apache.dubbo.spring.boot.sample.provider.service # Dubbo Application ## The default value of dubbo.application.name is ${spring.application.name} ## dubbo.application.name=${spring.application.name} diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java b/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java similarity index 94% rename from dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java rename to dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java index 9d3b389f3..43064b456 100644 --- a/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboExternalizedConfigurationConsumerBootstrap.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.consumer.bootstrap; +package org.apache.dubbo.spring.boot.sample.consumer.bootstrap; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java similarity index 90% rename from dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java rename to dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java index 2671f7513..6acdfcd40 100644 --- a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboExternalizedConfigurationProviderBootstrap.java @@ -14,9 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.provider.bootstrap; +package org.apache.dubbo.spring.boot.sample.provider.bootstrap; + +import org.apache.dubbo.spring.boot.sample.provider.service.DefaultDemoService; -import org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java similarity index 91% rename from dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java rename to dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java index 3e4c424e8..133ff4786 100644 --- a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.provider.service; +package org.apache.dubbo.spring.boot.sample.provider.service; import org.apache.dubbo.config.annotation.DubboService; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.springframework.beans.factory.annotation.Value; diff --git a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties index 400759a7b..c5f3fb35e 100644 --- a/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties +++ b/dubbo-spring-boot-samples/externalized-configuration-samples/provider-sample/src/main/resources/application.properties @@ -1,7 +1,7 @@ # Spring boot application spring.application.name=dubbo-externalized-configuration-provider-sample # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service -dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service +dubbo.scan.base-packages=org.apache.dubbo.spring.boot.sample.provider.service # Dubbo Application ## The default value of dubbo.application.name is ${spring.application.name} diff --git a/dubbo-spring-boot-samples/pom.xml b/dubbo-spring-boot-samples/pom.xml index 529b8f27c..f2eb29df2 100644 --- a/dubbo-spring-boot-samples/pom.xml +++ b/dubbo-spring-boot-samples/pom.xml @@ -38,6 +38,8 @@ externalized-configuration-samples registry-samples service-introspection-samples + servlet-container-samples + diff --git a/dubbo-spring-boot-samples/registry-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java b/dubbo-spring-boot-samples/registry-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java similarity index 92% rename from dubbo-spring-boot-samples/registry-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java rename to dubbo-spring-boot-samples/registry-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java index 7c8ed2f89..77fe06159 100644 --- a/dubbo-spring-boot-samples/registry-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java +++ b/dubbo-spring-boot-samples/registry-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboRegistryNacosConsumerBootstrap.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.consumer.bootstrap; +package org.apache.dubbo.spring.boot.sample.consumer.bootstrap; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java b/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java similarity index 89% rename from dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java rename to dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java index 64b523f4b..f1ee64b79 100644 --- a/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java +++ b/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboRegistryNacosProviderBootstrap.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.provider.bootstrap; +package org.apache.dubbo.spring.boot.sample.provider.bootstrap; -import org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService; +import org.apache.dubbo.spring.boot.sample.provider.service.DefaultDemoService; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; diff --git a/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java similarity index 91% rename from dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java rename to dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java index 3e4c424e8..133ff4786 100644 --- a/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java +++ b/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.provider.service; +package org.apache.dubbo.spring.boot.sample.provider.service; import org.apache.dubbo.config.annotation.DubboService; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.springframework.beans.factory.annotation.Value; diff --git a/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/resources/application.properties index 5dbc220dd..025fe15dc 100644 --- a/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/resources/application.properties +++ b/dubbo-spring-boot-samples/registry-samples/nacos-samples/provider-sample/src/main/resources/application.properties @@ -1,7 +1,7 @@ # Spring boot application spring.application.name=dubbo-registry-nacos-provider-sample # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service -dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service +dubbo.scan.base-packages=org.apache.dubbo.spring.boot.sample.provider.service # Dubbo Application ## The default value of dubbo.application.name is ${spring.application.name} diff --git a/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java b/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java similarity index 93% rename from dubbo-spring-boot-samples/registry-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java rename to dubbo-spring-boot-samples/registry-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java index d472c3923..efde86331 100644 --- a/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java +++ b/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboRegistryZooKeeperConsumerBootstrap.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.consumer.bootstrap; +package org.apache.dubbo.spring.boot.sample.consumer.bootstrap; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java b/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java similarity index 89% rename from dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java rename to dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java index ab3332157..4f00ab7f3 100644 --- a/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java +++ b/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboRegistryZooKeeperProviderBootstrap.java @@ -14,9 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.provider.bootstrap; +package org.apache.dubbo.spring.boot.sample.provider.bootstrap; -import org.apache.dubbo.spring.boot.demo.provider.service.DefaultDemoService; +import org.apache.dubbo.spring.boot.sample.provider.service.DefaultDemoService; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; diff --git a/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java similarity index 91% rename from dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java rename to dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java index 3e4c424e8..133ff4786 100644 --- a/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/demo/provider/service/DefaultDemoService.java +++ b/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java @@ -14,10 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.provider.service; +package org.apache.dubbo.spring.boot.sample.provider.service; import org.apache.dubbo.config.annotation.DubboService; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.springframework.beans.factory.annotation.Value; diff --git a/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/resources/application.properties index 516281800..e85f65154 100644 --- a/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/resources/application.properties +++ b/dubbo-spring-boot-samples/registry-samples/zookeeper-samples/provider-sample/src/main/resources/application.properties @@ -1,7 +1,7 @@ # Spring boot application spring.application.name=dubbo-registry-zookeeper-provider-sample # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service -dubbo.scan.base-packages=org.apache.dubbo.spring.boot.demo.provider.service +dubbo.scan.base-packages=org.apache.dubbo.spring.boot.sample.provider.service # Dubbo Application ## The default value of dubbo.application.name is ${spring.application.name} diff --git a/dubbo-spring-boot-samples/sample-api/pom.xml b/dubbo-spring-boot-samples/sample-api/pom.xml index 7cb6da567..bc73fab89 100644 --- a/dubbo-spring-boot-samples/sample-api/pom.xml +++ b/dubbo-spring-boot-samples/sample-api/pom.xml @@ -28,5 +28,6 @@ dubbo-spring-boot-sample-api Apache Dubbo Spring Boot :: Samples :: API + Apache Dubbo Spring Boot Samples API \ No newline at end of file diff --git a/dubbo-spring-boot-samples/sample-api/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/DemoService.java b/dubbo-spring-boot-samples/sample-api/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/DemoService.java similarity index 94% rename from dubbo-spring-boot-samples/sample-api/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/DemoService.java rename to dubbo-spring-boot-samples/sample-api/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/DemoService.java index 905e94e96..398591b8a 100644 --- a/dubbo-spring-boot-samples/sample-api/src/main/java/org/apache/dubbo/spring/boot/demo/consumer/DemoService.java +++ b/dubbo-spring-boot-samples/sample-api/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/DemoService.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.apache.dubbo.spring.boot.demo.consumer; +package org.apache.dubbo.spring.boot.sample.consumer; /** * Demo Service interface diff --git a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboNacosServiceIntrospectionConsumerBootstrap.java b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboNacosServiceIntrospectionConsumerBootstrap.java index 7c7819bee..d8baac3f1 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboNacosServiceIntrospectionConsumerBootstrap.java +++ b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboNacosServiceIntrospectionConsumerBootstrap.java @@ -17,7 +17,7 @@ package org.apache.dubbo.spring.boot.sample.consumer.bootstrap; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java index 1fd59e8a4..133ff4786 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java +++ b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java @@ -17,7 +17,7 @@ package org.apache.dubbo.spring.boot.sample.provider.service; import org.apache.dubbo.config.annotation.DubboService; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.springframework.beans.factory.annotation.Value; diff --git a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboZooKeeperServiceIntrospectionConsumerBootstrap.java b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboZooKeeperServiceIntrospectionConsumerBootstrap.java index 2d9787286..7ab2eb789 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboZooKeeperServiceIntrospectionConsumerBootstrap.java +++ b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboZooKeeperServiceIntrospectionConsumerBootstrap.java @@ -17,7 +17,7 @@ package org.apache.dubbo.spring.boot.sample.consumer.bootstrap; import org.apache.dubbo.config.annotation.DubboReference; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java index 1fd59e8a4..133ff4786 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java +++ b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java @@ -17,7 +17,7 @@ package org.apache.dubbo.spring.boot.sample.provider.service; import org.apache.dubbo.config.annotation.DubboService; -import org.apache.dubbo.spring.boot.demo.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; import org.springframework.beans.factory.annotation.Value; diff --git a/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/pom.xml b/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/pom.xml new file mode 100644 index 000000000..799086158 --- /dev/null +++ b/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/pom.xml @@ -0,0 +1,99 @@ + + + + org.apache.dubbo.samples + dubbo-spring-boot-servlet-container-samples + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-servlet-container-consumer-sample + Apache Dubbo Spring Boot :: Samples :: Servlet Container :: Consumer Sample + Apache Dubbo Spring Boot Servlet Container Consumer Sample + war + + + + + javax.servlet + javax.servlet-api + provided + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.apache.dubbo + dubbo-spring-boot-starter + ${revision} + + + + org.apache.dubbo + dubbo-spring-boot-actuator + ${revision} + + + + org.apache.dubbo.samples + dubbo-spring-boot-sample-api + ${revision} + + + + + + + + + org.apache.maven.plugins + maven-war-plugin + + false + + + + + + + org.apache.tomcat.maven + tomcat8-maven-plugin + 3.0-r1655215 + + + tomcat-run + + + exec-war-only + + package + + + / + 9090 + + + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboServletContainerConsumerBootstrap.java b/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboServletContainerConsumerBootstrap.java new file mode 100644 index 000000000..ec798a8aa --- /dev/null +++ b/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/src/main/java/org/apache/dubbo/spring/boot/sample/consumer/bootstrap/DubboServletContainerConsumerBootstrap.java @@ -0,0 +1,55 @@ +/* + * 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 org.apache.dubbo.spring.boot.sample.consumer.bootstrap; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import static org.springframework.web.bind.annotation.RequestMethod.GET; + +@EnableAutoConfiguration +@RestController +public class DubboServletContainerConsumerBootstrap extends SpringBootServletInitializer { + + @DubboReference(version = "${demo.service.version}", url = "${demo.service.url}") + private DemoService demoService; + + @RequestMapping(value = "/say-hello", method = GET) + public String sayHello(@RequestParam String name) { + return demoService.sayHello(name); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(getClass()); + } + + public static void main(String[] args) { // Run as the generic Spring Boot Web(Servlet) Application + SpringApplication application = new SpringApplication(DubboServletContainerConsumerBootstrap.class); + application.setWebApplicationType(WebApplicationType.SERVLET); + application.run(args); + } +} diff --git a/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/src/main/resources/application.yml b/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/src/main/resources/application.yml new file mode 100644 index 000000000..dffb18b86 --- /dev/null +++ b/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/src/main/resources/application.yml @@ -0,0 +1,8 @@ +spring: + application: + name: dubbo-servlet-container-consumer-sample + +demo: + service: + version: 1.0.0 + url: dubbo://127.0.0.1:23456 \ No newline at end of file diff --git a/dubbo-spring-boot-samples/servlet-container-samples/pom.xml b/dubbo-spring-boot-samples/servlet-container-samples/pom.xml new file mode 100644 index 000000000..b13785047 --- /dev/null +++ b/dubbo-spring-boot-samples/servlet-container-samples/pom.xml @@ -0,0 +1,35 @@ + + + + org.apache.dubbo.samples + dubbo-spring-boot-samples + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-servlet-container-samples + Apache Dubbo Spring Boot :: Samples :: Servlet Container + Apache Dubbo Spring Boot Servlet Container Samples + pom + + + provider-sample + consumer-sample + + + + + + Alfresco + Alfresco Repository + https://artifacts.alfresco.com/nexus/content/repositories/public/ + + false + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/pom.xml b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/pom.xml new file mode 100644 index 000000000..5f83ae533 --- /dev/null +++ b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/pom.xml @@ -0,0 +1,99 @@ + + + + org.apache.dubbo.samples + dubbo-spring-boot-servlet-container-samples + ${revision} + ../pom.xml + + 4.0.0 + + dubbo-spring-boot-servlet-container-provider-sample + Apache Dubbo Spring Boot :: Samples :: Servlet Container :: Provider Sample + Apache Dubbo Spring Boot Servlet Container Provider Sample + war + + + + + javax.servlet + javax.servlet-api + provided + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + org.apache.dubbo + dubbo-spring-boot-starter + ${revision} + + + + org.apache.dubbo + dubbo-spring-boot-actuator + ${revision} + + + + org.apache.dubbo.samples + dubbo-spring-boot-sample-api + ${revision} + + + + + + + + + org.apache.maven.plugins + maven-war-plugin + + false + + + + + + + org.apache.tomcat.maven + tomcat8-maven-plugin + 3.0-r1655215 + + + tomcat-run + + + exec-war-only + + package + + + / + + + + + + + + \ No newline at end of file diff --git a/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboServletContainerProviderBootstrap.java b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboServletContainerProviderBootstrap.java new file mode 100644 index 000000000..47c0a9260 --- /dev/null +++ b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/bootstrap/DubboServletContainerProviderBootstrap.java @@ -0,0 +1,60 @@ +/* + * 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 org.apache.dubbo.spring.boot.sample.provider.bootstrap; + +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; +import org.apache.dubbo.spring.boot.sample.provider.service.DefaultDemoService; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Dubbo Servlet Container Provider Bootstrap + * + * @see DefaultDemoService + * @since 2.7.7 + */ +@EnableAutoConfiguration +@RestController +public class DubboServletContainerProviderBootstrap extends SpringBootServletInitializer { + + @Autowired + private DemoService demoService; + + @RequestMapping("/say/{name}") + public String say(@PathVariable String name) { + return demoService.sayHello(name); + } + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(getClass()); + } + + public static void main(String[] args) { // Run as the generic Spring Boot Web(Servlet) Application + SpringApplication application = new SpringApplication(DubboServletContainerProviderBootstrap.class); + application.setWebApplicationType(WebApplicationType.SERVLET); + application.run(args); + } +} diff --git a/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java new file mode 100644 index 000000000..fa6433a47 --- /dev/null +++ b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/java/org/apache/dubbo/spring/boot/sample/provider/service/DefaultDemoService.java @@ -0,0 +1,43 @@ +/* + * 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 org.apache.dubbo.spring.boot.sample.provider.service; + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.spring.boot.sample.consumer.DemoService; + +import org.springframework.beans.factory.annotation.Value; + +/** + * Default {@link DemoService} + * + * @see DemoService + * @since 2.7.7 + */ +@DubboService(version = "${demo.service.version}") +public class DefaultDemoService implements DemoService { + + /** + * The default value of ${dubbo.application.name} is ${spring.application.name} + */ + @Value("${dubbo.application.name}") + private String serviceName; + + @Override + public String sayHello(String name) { + return String.format("[%s] : Hello, %s", serviceName, name); + } +} \ No newline at end of file diff --git a/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/resources/application.properties b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/resources/application.properties new file mode 100644 index 000000000..fe474cae6 --- /dev/null +++ b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/src/main/resources/application.properties @@ -0,0 +1,16 @@ +# Spring boot application +spring.application.name=dubbo-spring-boot-servlet-container-provider-sample +# Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service +dubbo.scan.base-packages=org.apache.dubbo.spring.boot.sample.provider.service + +# Dubbo Application + +# Dubbo Protocol +dubbo.protocol.name=dubbo +dubbo.protocol.port=23456 + +## Dubbo Registry +dubbo.registry.address=N/A + +## DemoService version +demo.service.version=1.0.0 \ No newline at end of file From f8748831a09b32f72becd9b5ea5d1ceeb3e6370b Mon Sep 17 00:00:00 2001 From: mercyblitz Date: Tue, 26 May 2020 16:43:25 +0800 Subject: [PATCH 2/4] Polish apache/dubbo-spring-boot-project#718 : [Samples] Introducing the samples deployed the external Servlet container --- README.md | 2 +- .../endpoint/DubboReferencesMetadataEndpoint.java | 3 ++- .../actuate/endpoint/DubboServicesMetadataEndpoint.java | 3 ++- .../endpoint/metadata/DubboReferencesMetadata.java | 3 ++- .../actuate/endpoint/metadata/DubboServicesMetadata.java | 3 ++- .../boot/autoconfigure/DubboAutoConfiguration.java | 9 ++++++--- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 34ac41718..0cd325468 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ If you still use the legacy Dubbo whose version is less than 2.7.0, please use t ### Build from Source -If you'd like to attempt to experience latest features, you also can build from source as follow: +If you'd like to attempt to experience the latest features, you also can build from the source code as follow: 1. Maven install current project in your local repository. > Maven install = `mvn install` diff --git a/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboReferencesMetadataEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboReferencesMetadataEndpoint.java index 40f04aab7..f2497da3f 100644 --- a/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboReferencesMetadataEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboReferencesMetadataEndpoint.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.spring.boot.actuate.endpoint; +import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboReferencesMetadata; @@ -26,7 +27,7 @@ import java.util.Map; /** - * Dubbo {@link Reference} Metadata {@link Endpoint} + * {@link DubboReference} Metadata {@link Endpoint} * * @since 2.7.0 */ diff --git a/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboServicesMetadataEndpoint.java b/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboServicesMetadataEndpoint.java index d1947da42..845dbc1f3 100644 --- a/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboServicesMetadataEndpoint.java +++ b/dubbo-spring-boot-actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/DubboServicesMetadataEndpoint.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.spring.boot.actuate.endpoint; +import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.AbstractDubboMetadata; import org.apache.dubbo.spring.boot.actuate.endpoint.metadata.DubboServicesMetadata; @@ -26,7 +27,7 @@ import java.util.Map; /** - * Dubbo {@link Service} Metadata {@link Endpoint} + * {@link DubboService} Metadata {@link Endpoint} * * @since 2.7.0 */ diff --git a/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboReferencesMetadata.java b/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboReferencesMetadata.java index d93ea3a16..6087015e3 100644 --- a/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboReferencesMetadata.java +++ b/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboReferencesMetadata.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.spring.boot.actuate.endpoint.metadata; +import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.spring.ReferenceBean; import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; @@ -26,7 +27,7 @@ import java.util.Map; /** - * Dubbo {@link Reference} Metadata + * {@link DubboReference} Metadata * * @since 2.7.0 */ diff --git a/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboServicesMetadata.java b/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboServicesMetadata.java index 5f1847cf4..11ce4d567 100644 --- a/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboServicesMetadata.java +++ b/dubbo-spring-boot-compatible/actuator/src/main/java/org/apache/dubbo/spring/boot/actuate/endpoint/metadata/DubboServicesMetadata.java @@ -16,6 +16,7 @@ */ package org.apache.dubbo.spring.boot.actuate.endpoint.metadata; +import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.spring.ServiceBean; import org.springframework.stereotype.Component; @@ -24,7 +25,7 @@ import java.util.Map; /** - * Dubbo {@link Service} Metadata + * {@link DubboService} Metadata * * @since 2.7.0 */ diff --git a/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java b/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java index 53b6dca26..6a190cbc9 100644 --- a/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java +++ b/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java @@ -16,8 +16,11 @@ */ package org.apache.dubbo.spring.boot.autoconfigure; +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.config.annotation.DubboService; import org.apache.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor; import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceAnnotationBeanPostProcessor; +import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceClassPostProcessor; import org.apache.dubbo.config.spring.context.annotation.DubboConfigConfiguration; import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; @@ -48,9 +51,9 @@ /** * Dubbo Auto {@link Configuration} * - * @see Reference - * @see Service - * @see ServiceAnnotationBeanPostProcessor + * @see DubboReference + * @see DubboService + * @see ServiceClassPostProcessor * @see ReferenceAnnotationBeanPostProcessor * @since 2.7.0 */ From 8d9a28cac0dc04c3486a2132edc48311fed539e6 Mon Sep 17 00:00:00 2001 From: mercyblitz Date: Tue, 26 May 2020 17:09:05 +0800 Subject: [PATCH 3/4] Polish apache/dubbo-spring-boot-project#718 : [Samples] Introducing the samples deployed the external Servlet container --- .../registry-samples/pom.xml | 16 ++++++++++++++++ .../nacos-samples/consumer-sample/pom.xml | 16 ++++++++++++++++ .../nacos-samples/pom.xml | 16 ++++++++++++++++ .../nacos-samples/provider-sample/pom.xml | 16 ++++++++++++++++ .../service-introspection-samples/pom.xml | 16 ++++++++++++++++ .../zookeeper-samples/consumer-sample/pom.xml | 16 ++++++++++++++++ .../zookeeper-samples/pom.xml | 16 ++++++++++++++++ .../zookeeper-samples/provider-sample/pom.xml | 16 ++++++++++++++++ .../consumer-sample/pom.xml | 16 ++++++++++++++++ .../servlet-container-samples/pom.xml | 16 ++++++++++++++++ .../provider-sample/pom.xml | 16 ++++++++++++++++ 11 files changed, 176 insertions(+) diff --git a/dubbo-spring-boot-samples/registry-samples/pom.xml b/dubbo-spring-boot-samples/registry-samples/pom.xml index 8417abcff..284fee7f3 100644 --- a/dubbo-spring-boot-samples/registry-samples/pom.xml +++ b/dubbo-spring-boot-samples/registry-samples/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/consumer-sample/pom.xml b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/consumer-sample/pom.xml index d7670d24f..0fb6c5f9b 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/consumer-sample/pom.xml +++ b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/consumer-sample/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/pom.xml b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/pom.xml index fd707e02b..29af9b14a 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/pom.xml +++ b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/provider-sample/pom.xml b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/provider-sample/pom.xml index 8a01061f7..6b709fd8b 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/provider-sample/pom.xml +++ b/dubbo-spring-boot-samples/service-introspection-samples/nacos-samples/provider-sample/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/service-introspection-samples/pom.xml b/dubbo-spring-boot-samples/service-introspection-samples/pom.xml index c4591b107..f7d0515a1 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/pom.xml +++ b/dubbo-spring-boot-samples/service-introspection-samples/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/consumer-sample/pom.xml b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/consumer-sample/pom.xml index 7c7fc29f1..7c6b0c7cf 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/consumer-sample/pom.xml +++ b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/consumer-sample/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/pom.xml b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/pom.xml index 1299fda31..0efedbfe1 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/pom.xml +++ b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/provider-sample/pom.xml b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/provider-sample/pom.xml index 3952adde4..8f0a6d2aa 100644 --- a/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/provider-sample/pom.xml +++ b/dubbo-spring-boot-samples/service-introspection-samples/zookeeper-samples/provider-sample/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/pom.xml b/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/pom.xml index 799086158..874a54af9 100644 --- a/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/pom.xml +++ b/dubbo-spring-boot-samples/servlet-container-samples/consumer-sample/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/servlet-container-samples/pom.xml b/dubbo-spring-boot-samples/servlet-container-samples/pom.xml index b13785047..3bc24d492 100644 --- a/dubbo-spring-boot-samples/servlet-container-samples/pom.xml +++ b/dubbo-spring-boot-samples/servlet-container-samples/pom.xml @@ -1,4 +1,20 @@ + diff --git a/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/pom.xml b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/pom.xml index 5f83ae533..463804df7 100644 --- a/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/pom.xml +++ b/dubbo-spring-boot-samples/servlet-container-samples/provider-sample/pom.xml @@ -1,4 +1,20 @@ + From e8b65c6589ee43ec5eedfb92a41543407c084a00 Mon Sep 17 00:00:00 2001 From: mercyblitz Date: Thu, 28 May 2020 12:19:40 +0800 Subject: [PATCH 4/4] Polish apache/dubbo-spring-boot-project#685 : Dubbo2.7.5: Duplicate ServiceBean found --- .../autoconfigure/DubboAutoConfiguration.java | 2 + .../ServiceBeanIdConflictProcessor.java | 115 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/beans/factory/config/ServiceBeanIdConflictProcessor.java diff --git a/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java b/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java index 6a190cbc9..6f130e89f 100644 --- a/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java +++ b/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/autoconfigure/DubboAutoConfiguration.java @@ -23,6 +23,7 @@ import org.apache.dubbo.config.spring.beans.factory.annotation.ServiceClassPostProcessor; import org.apache.dubbo.config.spring.context.annotation.DubboConfigConfiguration; import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig; +import org.apache.dubbo.spring.boot.beans.factory.config.ServiceBeanIdConflictProcessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -61,6 +62,7 @@ @Configuration @AutoConfigureAfter(DubboRelaxedBindingAutoConfiguration.class) @EnableConfigurationProperties(DubboConfigurationProperties.class) +@Import(ServiceBeanIdConflictProcessor.class) public class DubboAutoConfiguration { /** diff --git a/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/beans/factory/config/ServiceBeanIdConflictProcessor.java b/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/beans/factory/config/ServiceBeanIdConflictProcessor.java new file mode 100644 index 000000000..b6bf04be3 --- /dev/null +++ b/dubbo-spring-boot-compatible/autoconfigure/src/main/java/org/apache/dubbo/spring/boot/beans/factory/config/ServiceBeanIdConflictProcessor.java @@ -0,0 +1,115 @@ +/* + * 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 org.apache.dubbo.spring.boot.beans.factory.config; + +import org.apache.dubbo.config.ServiceConfig; +import org.apache.dubbo.config.spring.ServiceBean; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor; +import org.springframework.core.Ordered; +import org.springframework.core.PriorityOrdered; + +import java.util.HashMap; +import java.util.LinkedHashSet; +import java.util.Map; +import java.util.Objects; +import java.util.Set; + +import static org.springframework.util.ClassUtils.getUserClass; +import static org.springframework.util.ClassUtils.isAssignable; + +/** + * The post-processor for resolving the id conflict of {@link ServiceBean} when an interface is + * implemented by multiple services with different groups or versions that are exported on one provider + *

+ * Current implementation is a temporary resolution, and will be removed in the future. + * + * @see CommonAnnotationBeanPostProcessor + * @since 2.7.7 + * @deprecated + */ +public class ServiceBeanIdConflictProcessor implements MergedBeanDefinitionPostProcessor, DisposableBean, PriorityOrdered { + + /** + * The key is the class names of interfaces that were exported by {@link ServiceBean} + * The value is bean names of {@link ServiceBean} or {@link ServiceConfig}. + */ + private Map interfaceNamesToBeanNames = new HashMap<>(); + + /** + * Holds the bean names of {@link ServiceBean} or {@link ServiceConfig}. + */ + private Set conflictedBeanNames = new LinkedHashSet<>(); + + @Override + public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class beanType, String beanName) { + // Get raw bean type + Class rawBeanType = getUserClass(beanType); + if (isAssignable(ServiceConfig.class, rawBeanType)) { // ServiceConfig type or sub-type + String interfaceName = (String) beanDefinition.getPropertyValues().get("interface"); + String mappedBeanName = interfaceNamesToBeanNames.putIfAbsent(interfaceName, beanName); + // If mapped bean name exists and does not equal current bean name + if (mappedBeanName != null && !mappedBeanName.equals(beanName)) { + // conflictedBeanNames will record current bean name. + conflictedBeanNames.add(beanName); + } + } + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + if (conflictedBeanNames.contains(beanName) && bean instanceof ServiceConfig) { + ServiceConfig serviceConfig = (ServiceConfig) bean; + if (isConflictedServiceConfig(serviceConfig)) { + // Set id as the bean name + serviceConfig.setId(beanName); + } + + } + return bean; + } + + private boolean isConflictedServiceConfig(ServiceConfig serviceConfig) { + return Objects.equals(serviceConfig.getId(), serviceConfig.getInterface()); + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + + /** + * Keep the order being higher than {@link CommonAnnotationBeanPostProcessor#getOrder()} that is + * {@link Ordered#LOWEST_PRECEDENCE} + * + * @return {@link Ordered#LOWEST_PRECEDENCE} +1 + */ + @Override + public int getOrder() { + return LOWEST_PRECEDENCE + 1; + } + + @Override + public void destroy() throws Exception { + interfaceNamesToBeanNames.clear(); + conflictedBeanNames.clear(); + } +}