You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by li...@apache.org on 2021/01/15 02:01:20 UTC

[dubbo-samples] branch master updated: improve dubbo-samples-scala case (#257)

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

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new f643768  improve dubbo-samples-scala case (#257)
f643768 is described below

commit f643768a7732e8d3102a597e95598a6a5f1f2357
Author: daimingbao <da...@users.noreply.github.com>
AuthorDate: Fri Jan 15 10:01:13 2021 +0800

    improve dubbo-samples-scala case (#257)
---
 dubbo-samples-scala/case-configuration.yml         |  23 +++
 dubbo-samples-scala/pom.xml                        | 198 +++++----------------
 .../src/{ => main}/resources/log4j.properties      |   8 +-
 .../resources/spring}/dubbo-consumer.properties    |   4 +-
 .../resources/spring}/dubbo-provider.properties    |   4 +-
 .../scala/consumer/ConsumerConfiguration.scala     |   8 +-
 .../scala/consumer/StringServiceConsumer.scala     |  10 +-
 .../dubbo/samples/scala/provider/ProviderApp.scala |   2 +
 .../scala/provider/ProviderConfiguration.scala     |   6 +-
 .../scala/provider/impl/StringServiceImpl.scala    |   4 +-
 .../dubbo/samples/scala/ScalaServicesIT.scala      |  26 +++
 11 files changed, 119 insertions(+), 174 deletions(-)

diff --git a/dubbo-samples-scala/case-configuration.yml b/dubbo-samples-scala/case-configuration.yml
new file mode 100644
index 0000000..5c77b06
--- /dev/null
+++ b/dubbo-samples-scala/case-configuration.yml
@@ -0,0 +1,23 @@
+# 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.
+
+from: app-builtin-zookeeper.yml
+
+props:
+  project_name: dubbo-samples-scala
+  main_class: org.apache.dubbo.samples.scala.provider.ProviderApp
+  dubbo_port: 20880
+
diff --git a/dubbo-samples-scala/pom.xml b/dubbo-samples-scala/pom.xml
index 0014f2e..f94eafb 100644
--- a/dubbo-samples-scala/pom.xml
+++ b/dubbo-samples-scala/pom.xml
@@ -31,21 +31,8 @@
         <target.level>1.8</target.level>
         <spring.version>4.3.16.RELEASE</spring.version>
         <dubbo.version>2.7.7</dubbo.version>
-        <dubbo.rpc.version>2.7.5</dubbo.rpc.version>
-        <zookeeper.version>3.4.13</zookeeper.version>
-        <dubbo.configcenter.zookeeper.version>2.7.4</dubbo.configcenter.zookeeper.version>
-        <curator.version>4.0.1</curator.version>
-        <validation-api.version>1.1.0.Final</validation-api.version>
-        <hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
-        <resteasy.version>3.0.19.Final</resteasy.version>
-        <curator-client.version>4.0.1</curator-client.version>
-        <swagger.version>1.5.19</swagger.version>
-        <tomcat.version>7.0.88</tomcat.version>
-        <servlet.version>3.0.1</servlet.version>
-        <maven_checkstyle_version>3.0.0</maven_checkstyle_version>
-        <apache-rat-plugin.version>0.12</apache-rat-plugin.version>
-        <spring-boot.version>1.5.13.RELEASE</spring-boot.version>
         <scala.version>2.12.5</scala.version>
+        <junit.version>4.12</junit.version>
     </properties>
 
     <dependencyManagement>
@@ -58,14 +45,6 @@
                 <scope>import</scope>
             </dependency>
             <dependency>
-                <!-- Import dependency management from Spring Boot -->
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-dependencies</artifactId>
-                <version>${spring-boot.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
                 <groupId>io.netty</groupId>
                 <artifactId>netty-all</artifactId>
                 <version>4.1.16.Final</version>
@@ -79,122 +58,56 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo</artifactId>
+                <artifactId>dubbo-dependencies-zookeeper</artifactId>
                 <version>${dubbo.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.thrift</groupId>
-                        <artifactId>libthrift</artifactId>
-                    </exclusion>
-                </exclusions>
+                <type>pom</type>
             </dependency>
             <dependency>
                 <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo-rpc-rest</artifactId>
-                <version>${dubbo.rpc.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.zookeeper</groupId>
-                <artifactId>zookeeper</artifactId>
-                <version>${zookeeper.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.curator</groupId>
-                <artifactId>curator-framework</artifactId>
-                <version>${curator.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.zookeeper</groupId>
-                        <artifactId>zookeeper</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>javax.validation</groupId>
-                <artifactId>validation-api</artifactId>
-                <version>${validation-api.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.hibernate</groupId>
-                <artifactId>hibernate-validator</artifactId>
-                <version>${hibernate-validator.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.jboss.resteasy</groupId>
-                <artifactId>resteasy-jackson-provider</artifactId>
-                <version>${resteasy.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.curator</groupId>
-                <artifactId>curator-client</artifactId>
-                <version>${curator-client.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.zookeeper</groupId>
-                        <artifactId>zookeeper</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>javax.servlet</groupId>
-                <artifactId>javax.servlet-api</artifactId>
-                <version>${servlet.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.tomcat.embed</groupId>
-                <artifactId>tomcat-embed-core</artifactId>
-                <version>${tomcat.version}</version>
+                <artifactId>dubbo-configcenter-zookeeper</artifactId>
+                <version>${dubbo.version}</version>
             </dependency>
             <dependency>
-                <groupId>org.apache.tomcat.embed</groupId>
-                <artifactId>tomcat-embed-logging-juli</artifactId>
-                <version>${tomcat.version}</version>
+                <groupId>org.scala-lang</groupId>
+                <artifactId>scala-library</artifactId>
+                <version>${scala.version}</version>
             </dependency>
-            <!-- swagger -->
             <dependency>
-                <groupId>io.swagger</groupId>
-                <artifactId>swagger-annotations</artifactId>
-                <version>${swagger.version}</version>
+                <groupId>org.slf4j</groupId>
+                <artifactId>slf4j-simple</artifactId>
+                <version>1.7.25</version>
             </dependency>
             <dependency>
-                <groupId>io.swagger</groupId>
-                <artifactId>swagger-jaxrs</artifactId>
-                <version>${swagger.version}</version>
+                <groupId>junit</groupId>
+                <artifactId>junit</artifactId>
+                <version>${junit.version}</version>
             </dependency>
         </dependencies>
     </dependencyManagement>
 
     <dependencies>
         <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-framework</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>io.netty</groupId>
-                    <artifactId>netty</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.apache.zookeeper</groupId>
-                    <artifactId>zookeeper</artifactId>
-                </exclusion>
-            </exclusions>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
         </dependency>
         <dependency>
-            <groupId>org.apache.zookeeper</groupId>
-            <artifactId>zookeeper</artifactId>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo</artifactId>
+            <artifactId>dubbo-dependencies-zookeeper</artifactId>
+            <type>pom</type>
         </dependency>
         <dependency>
             <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo-configcenter-zookeeper</artifactId>
-            <version>${dubbo.configcenter.zookeeper.version}</version>
+            <artifactId>dubbo</artifactId>
         </dependency>
         <dependency>
-            <groupId>io.netty</groupId>
-            <artifactId>netty-all</artifactId>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo-configcenter-zookeeper</artifactId>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
@@ -207,21 +120,11 @@
         <dependency>
             <groupId>org.scala-lang</groupId>
             <artifactId>scala-library</artifactId>
-            <version>${scala.version}</version>
         </dependency>
     </dependencies>
 
     <build>
         <sourceDirectory>src/main/scala</sourceDirectory>
-        <pluginManagement>
-            <plugins>
-                <plugin>
-                    <groupId>org.springframework.boot</groupId>
-                    <artifactId>spring-boot-maven-plugin</artifactId>
-                    <version>${spring-boot.version}</version>
-                </plugin>
-            </plugins>
-        </pluginManagement>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -233,9 +136,28 @@
                 </configuration>
             </plugin>
             <plugin>
+                <groupId>net.alchim31.maven</groupId>
+                <artifactId>scala-maven-plugin</artifactId>
+                <version>3.3.3</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>compile</goal>
+                            <goal>testCompile</goal>
+                        </goals>
+                        <configuration>
+                            <args>
+                                <arg>-dependencyfile</arg>
+                                <arg>${project.build.directory}/.scala_dependencies</arg>
+                            </args>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
                 <groupId>org.apache.rat</groupId>
                 <artifactId>apache-rat-plugin</artifactId>
-                <version>${apache-rat-plugin.version}</version>
+                <version>0.12</version>
                 <executions>
                     <execution>
                         <id>verify.rat</id>
@@ -282,34 +204,6 @@
                     </execution>
                 </executions>
             </plugin>
-            <plugin>
-                <groupId>net.alchim31.maven</groupId>
-                <artifactId>scala-maven-plugin</artifactId>
-                <version>3.3.3</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>compile</goal>
-                            <goal>testCompile</goal>
-                        </goals>
-                        <configuration>
-                            <args>
-                                <arg>-dependencyfile</arg>
-                                <arg>${project.build.directory}/.scala_dependencies</arg>
-                            </args>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-surefire-plugin</artifactId>
-                <version>2.19</version>
-                <configuration>
-                    <useFile>false</useFile>
-                    <disableXmlReport>true</disableXmlReport>
-                </configuration>
-            </plugin>
         </plugins>
     </build>
 
@@ -324,7 +218,7 @@
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-checkstyle-plugin</artifactId>
-                        <version>${maven_checkstyle_version}</version>
+                        <version>3.0.0</version>
                         <dependencies>
                             <dependency>
                                 <groupId>com.puppycrawl.tools</groupId>
diff --git a/dubbo-samples-scala/src/resources/log4j.properties b/dubbo-samples-scala/src/main/resources/log4j.properties
similarity index 92%
rename from dubbo-samples-scala/src/resources/log4j.properties
rename to dubbo-samples-scala/src/main/resources/log4j.properties
index dcb78e2..bcc918a 100644
--- a/dubbo-samples-scala/src/resources/log4j.properties
+++ b/dubbo-samples-scala/src/main/resources/log4j.properties
@@ -1,23 +1,23 @@
 #
-#
 #   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.
-#  
 #
 
+###set log levels###
 log4j.rootLogger=info, stdout
+###output to the console###
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.Target=System.out
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
diff --git a/dubbo-samples-scala/src/resources/dubbo-consumer.properties b/dubbo-samples-scala/src/main/resources/spring/dubbo-consumer.properties
similarity index 85%
rename from dubbo-samples-scala/src/resources/dubbo-consumer.properties
rename to dubbo-samples-scala/src/main/resources/spring/dubbo-consumer.properties
index 7a10a3a..943b4b6 100644
--- a/dubbo-samples-scala/src/resources/dubbo-consumer.properties
+++ b/dubbo-samples-scala/src/main/resources/spring/dubbo-consumer.properties
@@ -17,6 +17,6 @@
 #  
 #
 
-dubbo.application.name=externalized-configuration-consumer
-dubbo.registry.address=zookeeper://127.0.0.1:2181
+dubbo.application.name=samples-scala-consumer
+dubbo.registry.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
 dubbo.consumer.timeout=3000
\ No newline at end of file
diff --git a/dubbo-samples-scala/src/resources/dubbo-provider.properties b/dubbo-samples-scala/src/main/resources/spring/dubbo-provider.properties
similarity index 85%
rename from dubbo-samples-scala/src/resources/dubbo-provider.properties
rename to dubbo-samples-scala/src/main/resources/spring/dubbo-provider.properties
index 4d1eeee..6e9ec67 100644
--- a/dubbo-samples-scala/src/resources/dubbo-provider.properties
+++ b/dubbo-samples-scala/src/main/resources/spring/dubbo-provider.properties
@@ -17,7 +17,7 @@
 #  
 #
 
-dubbo.application.name=externalized-configuration-provider
-dubbo.registry.address=zookeeper://127.0.0.1:2181
+dubbo.application.name=samples-scala-provider
+dubbo.registry.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
 dubbo.protocol.name=dubbo
 dubbo.protocol.port=20880
\ No newline at end of file
diff --git a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/consumer/ConsumerConfiguration.scala b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/consumer/ConsumerConfiguration.scala
index 85537b5..0327c80 100644
--- a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/consumer/ConsumerConfiguration.scala
+++ b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/consumer/ConsumerConfiguration.scala
@@ -19,13 +19,13 @@
 
 package org.apache.dubbo.samples.scala.consumer
 
-import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo
 import org.springframework.context.annotation.{ComponentScan, Configuration, PropertySource}
 
 @Configuration
-@EnableDubbo(scanBasePackages = Array("com.alibaba.dubbo.samples.scala.consumer"))
-@PropertySource(Array("classpath:/dubbo-consumer.properties"))
-@ComponentScan(value = Array("com.alibaba.dubbo.samples.scala.consumer"))
+@EnableDubbo(scanBasePackages = Array("org.apache.dubbo.samples.scala.consumer"))
+@PropertySource(Array("classpath:spring/dubbo-consumer.properties"))
+@ComponentScan(value = Array("org.apache.dubbo.samples.scala.consumer"))
 class ConsumerConfiguration {
 
 }
diff --git a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/consumer/StringServiceConsumer.scala b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/consumer/StringServiceConsumer.scala
index 94b7b20..cc2b026 100644
--- a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/consumer/StringServiceConsumer.scala
+++ b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/consumer/StringServiceConsumer.scala
@@ -19,16 +19,16 @@
 
 package org.apache.dubbo.samples.scala.consumer
 
-import com.alibaba.dubbo.config.annotation.Reference
+import org.apache.dubbo.config.annotation.DubboReference
 import org.apache.dubbo.samples.scala.service.StringService
 import org.springframework.stereotype.Component
 
-@Component("consumer")
+@Component("stringServiceConsumer")
 class StringServiceConsumer {
 
-  @Reference
-  private val greetingService: StringService = null
+  @DubboReference
+  private val stringService: StringService = null
 
-  def reverse(s: String): String = greetingService.reverse(s)
+  def reverse(s: String): String = stringService.reverse(s)
 
 }
diff --git a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/ProviderApp.scala b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/ProviderApp.scala
index 138197c..98fce9e 100644
--- a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/ProviderApp.scala
+++ b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/ProviderApp.scala
@@ -29,5 +29,7 @@ object ProviderApp extends App {
   val context = new AnnotationConfigApplicationContext(classOf[ProviderConfiguration])
   context.start()
 
+  println("dubbo service started")
+
   StdIn.readLine()
 }
diff --git a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/ProviderConfiguration.scala b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/ProviderConfiguration.scala
index 20be33f..389bed2 100644
--- a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/ProviderConfiguration.scala
+++ b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/ProviderConfiguration.scala
@@ -18,12 +18,12 @@
  */
 package org.apache.dubbo.samples.scala.provider
 
-import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo
 import org.springframework.context.annotation.{Configuration, PropertySource}
 
 @Configuration
-@EnableDubbo(scanBasePackages = Array("com.alibaba.dubbo.samples.scala.provider"))
-@PropertySource(Array("classpath:/dubbo-provider.properties"))
+@EnableDubbo(scanBasePackages = Array("org.apache.dubbo.samples.scala.provider"))
+@PropertySource(Array("classpath:spring/dubbo-provider.properties"))
 class ProviderConfiguration {
 
 }
\ No newline at end of file
diff --git a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/impl/StringServiceImpl.scala b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/impl/StringServiceImpl.scala
index 7c02da8..5a84d01 100644
--- a/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/impl/StringServiceImpl.scala
+++ b/dubbo-samples-scala/src/main/scala/org/apache/dubbo/samples/scala/provider/impl/StringServiceImpl.scala
@@ -19,10 +19,10 @@
 
 package org.apache.dubbo.samples.scala.provider.impl
 
-import com.alibaba.dubbo.config.annotation.Service
+import org.apache.dubbo.config.annotation.DubboService
 import org.apache.dubbo.samples.scala.service.StringService
 
-@Service
+@DubboService
 class StringServiceImpl extends StringService {
   override def reverse(s: String): String = s.reverse
 }
diff --git a/dubbo-samples-scala/src/test/scala/org/apache/dubbo/samples/scala/ScalaServicesIT.scala b/dubbo-samples-scala/src/test/scala/org/apache/dubbo/samples/scala/ScalaServicesIT.scala
new file mode 100644
index 0000000..37bf29f
--- /dev/null
+++ b/dubbo-samples-scala/src/test/scala/org/apache/dubbo/samples/scala/ScalaServicesIT.scala
@@ -0,0 +1,26 @@
+package org.apache.dubbo.samples.scala
+
+import org.apache.dubbo.samples.scala.consumer.{ConsumerConfiguration, StringServiceConsumer}
+import org.hamcrest.CoreMatchers.is
+import org.junit.Assert.assertThat
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.springframework.beans.factory.annotation.Autowired
+import org.springframework.test.context.ContextConfiguration
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
+
+
+@RunWith(classOf[SpringJUnit4ClassRunner])
+@ContextConfiguration(classes = Array(classOf[ConsumerConfiguration]))
+class ScalaServicesIT {
+
+  @Autowired
+  private val stringServiceConsumer: StringServiceConsumer  = null
+
+  @Test def testScala(): Unit = {
+    val response = stringServiceConsumer.reverse("hello world")
+    println("result: " + response)
+    assertThat(response, is("dlrow olleh"))
+  }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org