This is an automated email from the ASF dual-hosted git repository. liubao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
commit 68f3e14c0b02c2befbdb95302483f2f02688da59 Author: zhengyangyong <yangyong.zh...@huawei.com> AuthorDate: Wed Apr 25 11:51:48 2018 +0800 SCB-470 add spring boot starter provider archetype Signed-off-by: zhengyangyong <yangyong.zh...@huawei.com> --- archetypes/README.md | 7 +- .../servicecomb/archetypes/HelloConsumer.java | 1 + .../business-service-spring-boot-starter/README.md | 36 +++++++++ .../business-service-spring-boot-starter/pom.xml | 94 ++++++++++++++++++++++ .../servicecomb/archetypes/Application.java} | 18 ++--- .../servicecomb/archetypes/HelloConsumer.java | 6 +- .../servicecomb/archetypes/HelloEndpoint.java} | 18 +++-- .../src/main/resources/microservice.yaml | 43 ++++++++++ 8 files changed, 202 insertions(+), 21 deletions(-) diff --git a/archetypes/README.md b/archetypes/README.md index e71f2d0..8737aea 100644 --- a/archetypes/README.md +++ b/archetypes/README.md @@ -5,9 +5,14 @@ From http://maven.apache.org/guides/introduction/introduction-to-archetypes.html >In short, Archetype is a Maven project templating toolkit. An archetype is >defined as an original pattern or model from which all other things of the >same kind are made. The name fits as we are trying to provide a system that >provides a consistent means of generating Maven projects. Archetype will help >authors create Maven project templates for users, and provides users with the >means to generate parameterized versions of those project templates. ### What we provide -1. business-service-jaxrs +1. business-service-jaxrs + Archetype for create a common microservice using jaxrs provider. +2. business-service-spring-boot-starter + + Archetype for create a common microservice using spring-boot-starter provider. + more coming soon.. ### How to build these archetypes diff --git a/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java b/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java index e111383..26c6205 100644 --- a/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java +++ b/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java @@ -24,6 +24,7 @@ public class HelloConsumer { private final RestTemplate restTemplate = RestTemplateBuilder.create(); public void invokeHello(){ + //service url is : cse://serviceName/operation restTemplate.getForObject("cse://business-service/hello", String.class); } diff --git a/archetypes/business-service-spring-boot-starter/README.md b/archetypes/business-service-spring-boot-starter/README.md new file mode 100644 index 0000000..8c6424e --- /dev/null +++ b/archetypes/business-service-spring-boot-starter/README.md @@ -0,0 +1,36 @@ +## Welcome to use ServiceComb Java Chassis +This project(module) is generate by *org.apache.servicecomb.archetypes:business-service-spring-boot-starter-archetype*, it use **spring-boot-starter-provider** to develop service endpoint. + +### More works can be done further: +1. Modify "HelloEndpoint", add your business service logic, or create some new endpoints to provide your services. More details can be found : http://servicecomb.incubator.apache.org/users/develop-with-spring-boot-starter/ +2. Modify "microservice.yaml", change APPLICATION_ID, service_description.name, version, and service center address, endpoints publish address etc. More details can be found : http://servicecomb.incubator.apache.org/users/service-definition/ + +### Package your service +Under project(module) root folder, run +```bash +mvn package +``` +Then you can get executable jar in target/bin folder: +- xxxxxx-{version}-exec.jar +```bash +java -jar xxxxxx-{version}-exec.jar +``` +*Notice: If you need to modify config setting in "microservice.yaml" like service center address but don't want repackage the executable jar, **you can direct place a new "microservice.yaml" file in same folder, then settings will be overridden.*** + +## Spring Boot and ServiceComb +### Why ServiceComb make integration with Spring Boot +Spring Boot can accelerate develop speed of Spring application, it provider these features: +* Can create independent executable Spring application +* Tomcat embedded, Jetty as Web server, and do not need package(war) +* Provider many starter in order to simplify maven dependency + +Using Spring Boot in microservice development, can greatly simplifying configure and deploy. ServiceComb is a microservice framework with full functionality of service management, focus on rapidly development of microservices, so integration with Spring Boot can obtain greater advantages. + +### How ServiceComb make integration with Spring Boot +Developers often use Spring Boot in the following way: +* Java application : import `spring-boot-starter` then develop general application, does not contain WEB +* Web application : import `spring-boot-starter-web` then develop web application, also include an embedded Tomcat or Jetty server, and use Spring Web MVC framework to develop REST endpoints + +The first way, do not need any refactor, dfirect startup ServiceComb via Spring Boot. + +The second way is replace `Spring MVC DispatcherServlet` with `ServiceComb RestServlet`. \ No newline at end of file diff --git a/archetypes/business-service-spring-boot-starter/pom.xml b/archetypes/business-service-spring-boot-starter/pom.xml new file mode 100644 index 0000000..34c9e8b --- /dev/null +++ b/archetypes/business-service-spring-boot-starter/pom.xml @@ -0,0 +1,94 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <groupId>org.apache.servicecomb.archetypes</groupId> + <artifactId>business-service-spring-boot-starter</artifactId> + <modelVersion>4.0.0</modelVersion> + <version>1.0.0-m2-SNAPSHOT</version> + + <properties> + <java-chassis.version>1.0.0-m2-SNAPSHOT</java-chassis.version> + <springboot.version>1.4.5.RELEASE</springboot.version> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>java-chassis-dependencies</artifactId> + <version>${java-chassis.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter</artifactId> + </dependency> + <dependency> + <groupId>org.apache.servicecomb</groupId> + <artifactId>spring-boot-starter-provider</artifactId> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-validator</artifactId> + </dependency> + </dependencies> + + <!--for package and deploy--> + <build> + <plugins> + <plugin> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-maven-plugin</artifactId> + <version>${springboot.version}</version> + <executions> + <execution> + <goals> + <goal>repackage</goal> + </goals> + <configuration> + <outputDirectory>${project.build.directory}/bin</outputDirectory> + <classifier>exec</classifier> + </configuration> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <version>2.6</version> + <configuration> + <archive> + <manifestEntries> + <Class-Path>.</Class-Path> + </manifestEntries> + </archive> + </configuration> + </plugin> + </plugins> + </build> + +</project> \ No newline at end of file diff --git a/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java b/archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/Application.java similarity index 70% copy from archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java copy to archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/Application.java index e111383..2309563 100644 --- a/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java +++ b/archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/Application.java @@ -17,14 +17,14 @@ package org.apache.servicecomb.archetypes; -import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder; -import org.springframework.web.client.RestTemplate; +import org.apache.servicecomb.springboot.starter.provider.EnableServiceComb; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; -public class HelloConsumer { - private final RestTemplate restTemplate = RestTemplateBuilder.create(); - - public void invokeHello(){ - restTemplate.getForObject("cse://business-service/hello", String.class); +@SpringBootApplication +@EnableServiceComb +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); } - -} +} \ No newline at end of file diff --git a/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java b/archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java similarity index 93% copy from archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java copy to archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java index e111383..73917fd 100644 --- a/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java +++ b/archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java @@ -23,8 +23,8 @@ import org.springframework.web.client.RestTemplate; public class HelloConsumer { private final RestTemplate restTemplate = RestTemplateBuilder.create(); - public void invokeHello(){ + public void invokeHello() { + //service url is : cse://serviceName/operation restTemplate.getForObject("cse://business-service/hello", String.class); } - -} +} \ No newline at end of file diff --git a/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java b/archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/HelloEndpoint.java similarity index 69% copy from archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java copy to archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/HelloEndpoint.java index e111383..888dbce 100644 --- a/archetypes/business-service-jaxrs/src/main/java/org/apache/servicecomb/archetypes/HelloConsumer.java +++ b/archetypes/business-service-spring-boot-starter/src/main/java/org/apache/servicecomb/archetypes/HelloEndpoint.java @@ -17,14 +17,16 @@ package org.apache.servicecomb.archetypes; -import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder; -import org.springframework.web.client.RestTemplate; +import org.apache.servicecomb.provider.rest.common.RestSchema; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; -public class HelloConsumer { - private final RestTemplate restTemplate = RestTemplateBuilder.create(); +@RestSchema(schemaId = "helloEndpoint") +@RequestMapping(path = "/") +public class HelloEndpoint { - public void invokeHello(){ - restTemplate.getForObject("cse://business-service/hello", String.class); + @GetMapping(path = "/hello") + public String hello() { + return "Hello World!"; } - -} +} \ No newline at end of file diff --git a/archetypes/business-service-spring-boot-starter/src/main/resources/microservice.yaml b/archetypes/business-service-spring-boot-starter/src/main/resources/microservice.yaml new file mode 100644 index 0000000..ddf5f39 --- /dev/null +++ b/archetypes/business-service-spring-boot-starter/src/main/resources/microservice.yaml @@ -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. +## --------------------------------------------------------------------------- + +#More details can be found : +# 1.http://servicecomb.incubator.apache.org/users/service-definition/ +# 2.http://servicecomb.incubator.apache.org/users/service-configurations/ +# 3.http://servicecomb.incubator.apache.org/users/communicate-protocol/ + +#Indicates an application name +APPLICATION_ID: business +service_description: +#Indicates a microservice name +#The microservice name should be unique within an application. +#The name can contain digits, uppercase and lowercase letters, hyphens(-), underscores(_), and periods(.); and can neither start nor end with punctuations. +#The naming rule is as follows: ^[a-zA-Z0-9]+$|^[a-zA-Z0-9][a-zA-Z0-9_-.]*[a-zA-Z0-9]$. + name: business-service +#Indicates a service version + version: 1.0.0 +cse: + service: + #Specifies the service center IP address. + registry: + address: http://127.0.0.1:30100 + #Specifies the rest transport listening IP address. + rest: + address: 0.0.0.0:8080 + #Specifies the highway transport listening IP address. + highway: + address: 0.0.0.0:7070 \ No newline at end of file -- To stop receiving notification emails like this one, please contact liu...@apache.org.