You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/02/04 06:54:45 UTC

[dubbo-spi-extensions] 19/44: 增加使用 spring-cloud-starter-dubbo

This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch 2.7.x
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-extensions.git

commit 955ac3d31885ea08c612f1f0a1f8cf1775a62585
Author: qq213539 <21...@qq.com>
AuthorDate: Fri Dec 4 17:58:14 2020 +0800

    增加使用 spring-cloud-starter-dubbo
---
 .../examples-provider-sca/pom.xml                  |  27 +++++
 .../apidocs/examples/ExampleScaApplication.java    |  43 +++++++
 .../apidocs/examples/api/impl/AsyncDemoImpl.java   | 104 +++++++++++++++++
 .../apidocs/examples/api/impl/SyncDemoImpl.java    | 125 +++++++++++++++++++++
 .../dubbo/apidocs/examples/cfg/DubboDocConfig.java |  34 ++++++
 dubbo-api-docs/dubbo-api-docs-examples/pom.xml     |  17 +++
 dubbo-api-docs/dubbo-api-docs-ui-server/pom.xml    |  17 +--
 dubbo-api-docs/pom.xml                             |   4 +
 8 files changed, 360 insertions(+), 11 deletions(-)

diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/pom.xml b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/pom.xml
index 6cd0781..7765916 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/pom.xml
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/pom.xml
@@ -29,6 +29,33 @@
 
     <dependencies>
 
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-api-docs-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.dubbo.examples.apidocs</groupId>
+            <artifactId>examples-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-autoconfigure</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-dubbo</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-logging</artifactId>
+        </dependency>
+
     </dependencies>
 
 
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/ExampleScaApplication.java b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/ExampleScaApplication.java
new file mode 100644
index 0000000..a6f600f
--- /dev/null
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/ExampleScaApplication.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.apidocs.examples;
+
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+
+import org.springframework.boot.WebApplicationType;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.builder.SpringApplicationBuilder;
+import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
+
+/**
+ * example dubbo provider service using spring-cloud-starter-dubbo.
+ * @author klw(213539@qq.com)
+ * `2020/12/4` 17:48
+ */
+@SpringBootApplication
+@EnableDiscoveryClient
+@EnableDubbo(scanBasePackages = {"org.apache.dubbo.apidocs.examples.api"})
+public class ExampleScaApplication {
+
+    public static void main(String[] args) {
+        new SpringApplicationBuilder(ExampleScaApplication.class)
+                // Non web applications
+                .web(WebApplicationType.NONE)
+                .run(args);
+    }
+
+}
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/api/impl/AsyncDemoImpl.java b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/api/impl/AsyncDemoImpl.java
new file mode 100644
index 0000000..b4f14fb
--- /dev/null
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/api/impl/AsyncDemoImpl.java
@@ -0,0 +1,104 @@
+/*
+ * 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.apidocs.examples.api.impl;
+
+import org.apache.dubbo.apidocs.annotations.ApiDoc;
+import org.apache.dubbo.apidocs.annotations.ApiModule;
+import org.apache.dubbo.apidocs.examples.api.IAsyncDemo;
+import org.apache.dubbo.apidocs.examples.params.DemoParamBean1;
+import org.apache.dubbo.apidocs.examples.params.DemoParamBean2;
+import org.apache.dubbo.apidocs.examples.params.DemoParamBean3;
+import org.apache.dubbo.apidocs.examples.params.DemoParamBean4;
+import org.apache.dubbo.apidocs.examples.responses.DemoRespBean1;
+import org.apache.dubbo.config.annotation.DubboService;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * Asynchronous demo implementation.
+ * @author klw(213539@qq.com)
+ * 2020/12/4 17:53
+ */
+@DubboService(async = true)
+@ApiModule(value = "Asynchronous demo", apiInterface = IAsyncDemo.class)
+public class AsyncDemoImpl implements IAsyncDemo {
+
+    public static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 40 * 3);
+
+    @ApiDoc("request and response parameters are beans")
+    @Override
+    public CompletableFuture<DemoRespBean1> demoApi1(DemoParamBean1 param1, DemoParamBean2 param2) {
+        DemoRespBean1 result = new DemoRespBean1();
+        result.setCode("123456789");
+        result.setMessage("called demoApi1 msg1");
+        result.setMessage2("called demoApi1 msg2");
+        return CompletableFuture.supplyAsync(() -> result, EXECUTOR);
+    }
+
+    @Override
+    @ApiDoc(value = "Map without generics", responseClassDescription="Map without generics")
+    public CompletableFuture<Map> demoApi6() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "Map generic with Object", responseClassDescription="Map generic with Object")
+    public CompletableFuture<Map<Object, Object>> demoApi7() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "List without generics", responseClassDescription="List without generics")
+    public CompletableFuture<List> demoApi10() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "List generic with Object", responseClassDescription="List generic with Object")
+    public CompletableFuture<List<Object>> demoApi9() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "Object", responseClassDescription="Object")
+    public CompletableFuture<Object> demoApi8() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "Integer", responseClassDescription="Integer")
+    public CompletableFuture<Integer> demoApi11() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "many generics", responseClassDescription="many generics")
+    public CompletableFuture<List<List<String>>> demoApi12(){
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "Simple test", responseClassDescription = "Simple test")
+    public CompletableFuture<DemoParamBean3> demoApi13(DemoParamBean3 param1, DemoParamBean4 param2) {
+        DemoParamBean3 result = new DemoParamBean3();
+        result.setString("demoApi13 result");
+        return CompletableFuture.supplyAsync(() -> result, EXECUTOR);
+    }
+}
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/api/impl/SyncDemoImpl.java b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/api/impl/SyncDemoImpl.java
new file mode 100644
index 0000000..60b6827
--- /dev/null
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/api/impl/SyncDemoImpl.java
@@ -0,0 +1,125 @@
+/*
+ * 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.apidocs.examples.api.impl;
+
+import org.apache.dubbo.apidocs.annotations.ApiDoc;
+import org.apache.dubbo.apidocs.annotations.ApiModule;
+import org.apache.dubbo.apidocs.annotations.RequestParam;
+import org.apache.dubbo.apidocs.examples.api.ISyncDemo;
+import org.apache.dubbo.apidocs.examples.params.DemoParamBean1;
+import org.apache.dubbo.apidocs.examples.params.DemoParamBean2;
+import org.apache.dubbo.apidocs.examples.params.DemoParamBean3;
+import org.apache.dubbo.apidocs.examples.params.DemoParamBean4;
+import org.apache.dubbo.apidocs.examples.responses.BaseResponse;
+import org.apache.dubbo.apidocs.examples.responses.DemoRespBean1;
+import org.apache.dubbo.config.annotation.DubboService;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Synchronous demo implementation.
+ * @author klw(213539@qq.com)
+ * 2020/12/4 17:53
+ */
+@Slf4j
+@DubboService
+@ApiModule(value = "Synchronous demo", apiInterface = ISyncDemo.class)
+public class SyncDemoImpl implements ISyncDemo {
+
+    @ApiDoc("request and response parameters are beans")
+    @Override
+    public DemoRespBean1 demoApi1(DemoParamBean1 param1, DemoParamBean2 param2) {
+        log.info("called demoApi1");
+        DemoRespBean1 result = new DemoRespBean1();
+        result.setCode("123456789");
+        result.setMessage("called demoApi1 msg1");
+        result.setMessage2("called demoApi1 msg2");
+        return result;
+    }
+
+    @ApiDoc(value = "request and response parameters are Strings", responseClassDescription="A string")
+    @Override
+    public String demoApi2(@RequestParam(value = "Parameter 1", required = true) String prarm1, String prarm2) {
+        log.info(" called demoApi2");
+        return "demoApi2";
+    }
+
+    @Override
+    public String demoApi3(String prarm1) {
+        return null;
+    }
+
+    @ApiDoc(value = "Nonparametric method with Dubbo doc annotation", responseClassDescription="A string")
+    @Override
+    public String demoApi4() {
+        return "asdfasdfsdafds";
+    }
+
+    @ApiDoc(value = " Use generics in response", responseClassDescription=" Use generics in response")
+    public BaseResponse<DemoRespBean1> demoApi5(){
+        BaseResponse<DemoRespBean1> response = new BaseResponse<>();
+        DemoRespBean1 responseData = new DemoRespBean1();
+        responseData.setCode("2222");
+        responseData.setMessage("msg1");
+        responseData.setMessage2("msg2");
+        response.setData(responseData);
+        response.setCode("1111");
+        response.setMessage("msg");
+        return response;
+    }
+
+    @Override
+    @ApiDoc(value = "Map without generics", responseClassDescription="Map without generics")
+    public Map demoApi6() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "Map generic with Object", responseClassDescription="Map generic with Object")
+    public Map<Object, Object> demoApi7() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "List without generics", responseClassDescription="List without generics")
+    public List demoApi10() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "List generic with Object", responseClassDescription="List generic with Object")
+    public List<Object> demoApi9() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "Object", responseClassDescription="Object")
+    public Object demoApi8() {
+        return null;
+    }
+
+    @Override
+    @ApiDoc(value = "Simple test", responseClassDescription = "Simple test")
+    public DemoParamBean3 demoApi13(DemoParamBean3 param1, DemoParamBean4 param2) {
+        DemoParamBean3 result = new DemoParamBean3();
+        result.setString("demoApi13 result");
+        return result;
+    }
+}
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/cfg/DubboDocConfig.java b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/cfg/DubboDocConfig.java
new file mode 100644
index 0000000..d832f7d
--- /dev/null
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/java/org/apache/dubbo/apidocs/examples/cfg/DubboDocConfig.java
@@ -0,0 +1,34 @@
+/*
+ * 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.apidocs.examples.cfg;
+
+import org.apache.dubbo.apidocs.EnableDubboApiDocs;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+
+/**
+ * dubbo doc config.
+ * @author klw(213539@qq.com)
+ * 2020/12/4 17:52
+ */
+@Configuration
+// Enable dubbo api doc
+@EnableDubboApiDocs
+@Profile("dev")
+public class DubboDocConfig {
+}
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/pom.xml b/dubbo-api-docs/dubbo-api-docs-examples/pom.xml
index 61862fe..1fe85e5 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/pom.xml
+++ b/dubbo-api-docs/dubbo-api-docs-examples/pom.xml
@@ -40,6 +40,23 @@
 
     <dependencyManagement>
         <dependencies>
+
+            <dependency>
+                <groupId>org.springframework.cloud</groupId>
+                <artifactId>spring-cloud-dependencies</artifactId>
+                <version>${spring-cloud.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
+            <dependency>
+                <groupId>com.alibaba.cloud</groupId>
+                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
+                <version>${spring-cloud-alibaba-dependencies.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+
             <!-- Internal libs -->
             <dependency>
                 <groupId>org.apache.dubbo.examples.apidocs</groupId>
diff --git a/dubbo-api-docs/dubbo-api-docs-ui-server/pom.xml b/dubbo-api-docs/dubbo-api-docs-ui-server/pom.xml
index 7698683..32a7230 100644
--- a/dubbo-api-docs/dubbo-api-docs-ui-server/pom.xml
+++ b/dubbo-api-docs/dubbo-api-docs-ui-server/pom.xml
@@ -241,17 +241,6 @@
                 <finalName>dubbo-api-docs-ui-server</finalName>
                 <plugins>
                     <plugin>
-                        <artifactId>maven-jar-plugin</artifactId>
-                        <configuration>
-                            <archive>
-                                <manifest>
-                                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
-                                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
-                                </manifest>
-                            </archive>
-                        </configuration>
-                    </plugin>
-                    <plugin>
                         <groupId>org.springframework.boot</groupId>
                         <artifactId>spring-boot-maven-plugin</artifactId>
                         <configuration>
@@ -270,6 +259,12 @@
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-jar-plugin</artifactId>
                         <configuration>
+                            <archive>
+                                <manifest>
+                                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+                                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+                                </manifest>
+                            </archive>
                             <excludes>
                                 <exclude>**/application.yml</exclude>
                                 <exclude>**/log4j2.xml</exclude>
diff --git a/dubbo-api-docs/pom.xml b/dubbo-api-docs/pom.xml
index 706b315..96a5a09 100644
--- a/dubbo-api-docs/pom.xml
+++ b/dubbo-api-docs/pom.xml
@@ -21,6 +21,7 @@
         <groupId>org.apache</groupId>
         <artifactId>apache</artifactId>
         <version>19</version>
+        <relativePath/>
     </parent>
     <groupId>org.apache.dubbo</groupId>
     <artifactId>dubbo-api-docs</artifactId>
@@ -46,6 +47,9 @@
         <disruptor.version>3.4.2</disruptor.version>
         <springfox.version>3.0.0</springfox.version>
         <nacos.version>1.4.0</nacos.version>
+
+        <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
+        <spring-cloud-alibaba-dependencies.version>2.2.3.RELEASE</spring-cloud-alibaba-dependencies.version>
     </properties>
 
     <dependencyManagement>