mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 21:57:56 +08:00
3.2.0
This commit is contained in:
@@ -10,8 +10,6 @@
|
||||
|
||||
<modules>
|
||||
<module>sop-story</module>
|
||||
<module>sop-book</module>
|
||||
<module>sop-easyopen</module>
|
||||
<module>sop-springmvc</module>
|
||||
</modules>
|
||||
</project>
|
@@ -1,7 +1,5 @@
|
||||
# 服务示例
|
||||
|
||||
- sop-story:微服务示例,story服务,同时作为Provider提供服务。本地文档:http://localhost:2222/doc.html
|
||||
- sop-book:微服务示例,book服务,也是Consumer,调用story提供的服务
|
||||
- sop-story:微服务示例
|
||||
- sop-auth:应用授权示例
|
||||
- sop-springmvc:springmvc工程实例
|
||||
- sop-easyopen:整合easyopen示例
|
||||
|
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-book-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>sop-book-api</module>
|
||||
<module>sop-book-web</module>
|
||||
</modules>
|
||||
</project>
|
25
sop-example/sop-book/sop-book-api/.gitignore
vendored
25
sop-example/sop-book/sop-book-api/.gitignore
vendored
@@ -1,25 +0,0 @@
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-book-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
@@ -1,12 +0,0 @@
|
||||
package com.gitee.book.api.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class Book {
|
||||
private int id;
|
||||
private String name;
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
package com.gitee.book.api.service;
|
||||
|
||||
import com.gitee.book.api.domain.Book;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RequestMapping("/book")
|
||||
public interface BookService {
|
||||
@RequestMapping("/getBook")
|
||||
Book getBook(@RequestParam("id") int id);
|
||||
}
|
25
sop-example/sop-book/sop-book-web/.gitignore
vendored
25
sop-example/sop-book/sop-book-web/.gitignore
vendored
@@ -1,25 +0,0 @@
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
@@ -1,147 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-book-web</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>sop-book</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<dubbo.version>2.6.5</dubbo.version>
|
||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
|
||||
<!-- nacos spring cloud版本号 -->
|
||||
<spring-cloud-alibaba-nacos.version>0.9.0.RELEASE</spring-cloud-alibaba-nacos.version>
|
||||
<!-- nacos客户端版本号 -->
|
||||
<nacos-client.version>1.1.3</nacos-client.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-service-common</artifactId>
|
||||
<version>3.1.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-book-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-story-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- 使用nacos注册中心
|
||||
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
|
||||
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
<version>${spring-cloud-alibaba-nacos.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos-client.version}</version>
|
||||
</dependency>
|
||||
<!-- 注册中心end -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Dubbo Spring Boot Starter -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>0.2.1.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-models</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
<artifactId>swagger-models</artifactId>
|
||||
<version>1.5.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
@@ -1,20 +0,0 @@
|
||||
package com.gitee.sop.bookweb;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
// 允许调用其他服务
|
||||
@EnableFeignClients
|
||||
// 服务注册
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class SopBookApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SopBookApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,33 +0,0 @@
|
||||
package com.gitee.sop.bookweb.config;
|
||||
|
||||
import com.gitee.sop.servercommon.configuration.AlipayServiceConfiguration;
|
||||
import com.gitee.sop.servercommon.swagger.SwaggerSupport;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
/**
|
||||
* 使用支付宝开放平台功能
|
||||
* @author tanghc
|
||||
*/
|
||||
@Configuration
|
||||
public class OpenServiceConfig extends AlipayServiceConfiguration {
|
||||
|
||||
// 开启文档
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
public static class Swagger2 extends SwaggerSupport {
|
||||
@Override
|
||||
protected String getDocTitle() {
|
||||
return "图书API";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用淘宝开放平台功能
|
||||
* @author tanghc
|
||||
*/
|
||||
//@Configuration
|
||||
//public class OpenServiceConfig extends TaobaoServiceConfiguration {
|
||||
//
|
||||
//}
|
@@ -1,14 +0,0 @@
|
||||
package com.gitee.sop.bookweb.consumer;
|
||||
|
||||
import com.gitee.sop.story.api.service.StoryService;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
||||
/**
|
||||
* 调用story服务
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
// value对应的spring.application.name
|
||||
@FeignClient("story-service")
|
||||
public interface StoryServiceConsumer extends StoryService {
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
package com.gitee.sop.bookweb.controller;
|
||||
|
||||
import com.gitee.book.api.domain.Book;
|
||||
import com.gitee.sop.bookweb.consumer.StoryServiceConsumer;
|
||||
import com.gitee.sop.bookweb.param.BookParam;
|
||||
import com.gitee.sop.bookweb.vo.BookVO;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 这里演示如何接受业务参数。
|
||||
* @author tanghc
|
||||
*/
|
||||
@Api(tags = "图书接口")
|
||||
@RestController
|
||||
public class AlipayBookController {
|
||||
|
||||
@Autowired
|
||||
StoryServiceConsumer storyServiceConsumer;
|
||||
|
||||
@ApiOperation(value="查询书本信息", notes = "可以根据ISBN查询书本信息")
|
||||
@ApiMapping(value = "book.search")
|
||||
public BookVO searchBook(BookParam param) {
|
||||
BookVO bookVO = new BookVO();
|
||||
bookVO.setId(1);
|
||||
bookVO.setName("白雪公主,ISBN:" + param.getIsbn());
|
||||
bookVO.setIsbn("ABCSSSSDDD");
|
||||
return bookVO;
|
||||
}
|
||||
|
||||
@ApiMapping(value = "alipay.book.get")
|
||||
public Book getBook() {
|
||||
Book story = new Book();
|
||||
story.setId(1);
|
||||
story.setName("白雪公主(alipay.book.get)");
|
||||
return story;
|
||||
}
|
||||
|
||||
// 通过Feign调用story服务
|
||||
@ApiMapping(value = "alipay.book.story.get")
|
||||
public Object getBook2() {
|
||||
Story story = new Story();
|
||||
story.setId(1);
|
||||
story.setName("白雪公主(alipay.book.story.get)");
|
||||
Story story2 = storyServiceConsumer.getStory(1);
|
||||
return Arrays.asList(story, story2);
|
||||
}
|
||||
|
||||
}
|
@@ -1,72 +0,0 @@
|
||||
package com.gitee.sop.bookweb.controller;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 默认的结果封装类.
|
||||
* <pre>
|
||||
*
|
||||
* xml返回结果:
|
||||
* <response>
|
||||
* <code>50</code>
|
||||
* <msg>Remote service error</msg>
|
||||
* <sub_code>isv.invalid-parameter</sub_code>
|
||||
* <sub_msg>非法参数</sub_msg>
|
||||
* </response>
|
||||
* 成功情况:
|
||||
* <response>
|
||||
* <code>0</code>
|
||||
* <msg>成功消息</msg>
|
||||
* <data>
|
||||
* ...返回内容
|
||||
* </data>
|
||||
* </response>
|
||||
*
|
||||
* json返回格式:
|
||||
* {
|
||||
* "code":"50",
|
||||
* "msg":"Remote service error",
|
||||
* "sub_code":"isv.invalid-parameter",
|
||||
* "sub_msg":"非法参数"
|
||||
* }
|
||||
* 成功情况:
|
||||
* {
|
||||
* "code":"0",
|
||||
* "msg":"成功消息内容。。。",
|
||||
* "data":{
|
||||
* ...返回内容
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* 字段说明:
|
||||
* code:网关异常码 <br>
|
||||
* msg:网关异常信息 <br>
|
||||
* sub_code:业务异常码 <br>
|
||||
* sub_msg:业务异常信息 <br>
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class ApiResult {
|
||||
|
||||
/**
|
||||
* 网关异常信息
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 业务异常码
|
||||
*/
|
||||
private String sub_msg;
|
||||
|
||||
/**
|
||||
* 业务异常信息
|
||||
*/
|
||||
private String sub_code;
|
||||
|
||||
/**
|
||||
* 返回结果
|
||||
*/
|
||||
private Object data;
|
||||
}
|
@@ -1,73 +0,0 @@
|
||||
package com.gitee.sop.bookweb.controller;
|
||||
|
||||
import com.gitee.book.api.domain.Book;
|
||||
import com.gitee.sop.bookweb.consumer.StoryServiceConsumer;
|
||||
import com.gitee.sop.bookweb.param.BookParam;
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import com.gitee.book.api.service.BookService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* book服务
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class BookController implements BookService {
|
||||
|
||||
@Autowired
|
||||
StoryServiceConsumer storyServiceConsumer;
|
||||
|
||||
@Override
|
||||
public Book getBook(int id) {
|
||||
Book book = new Book();
|
||||
book.setId(id);
|
||||
book.setName("汪汪队");
|
||||
return book;
|
||||
}
|
||||
|
||||
@RequestMapping("listBookAndStory")
|
||||
public Object listBookAndStory(int id) {
|
||||
Book book = new Book();
|
||||
book.setId(id);
|
||||
book.setName("汪汪队");
|
||||
|
||||
// 调用story服务
|
||||
Story story = storyServiceConsumer.getStory(id);
|
||||
|
||||
return Arrays.asList(book, story);
|
||||
}
|
||||
|
||||
@RequestMapping("getBook2")
|
||||
public Object getBookError(int id) {
|
||||
if (id == 0) {
|
||||
throw new RuntimeException("id不能为空");
|
||||
}
|
||||
Book book = new Book();
|
||||
book.setId(id);
|
||||
book.setName("汪汪队");
|
||||
return Arrays.asList(book);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping("getBook3")
|
||||
public Object getBook3(@RequestBody BookParam param) {
|
||||
if (param.getId() == 0) {
|
||||
throw new RuntimeException("id不能为空");
|
||||
}
|
||||
Book book = new Book();
|
||||
book.setId(param.getId());
|
||||
book.setName("小马宝莉");
|
||||
|
||||
ApiResult apiResult = new ApiResult();
|
||||
apiResult.setData(book);
|
||||
return apiResult;
|
||||
}
|
||||
|
||||
}
|
@@ -1,40 +0,0 @@
|
||||
package com.gitee.sop.bookweb.controller;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import com.gitee.sop.story.api.param.DemoParam;
|
||||
import com.gitee.sop.story.api.result.DemoResult;
|
||||
import com.gitee.sop.story.api.service.DemoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 调用dubbo服务,provider是story,见DefaultDemoService.java
|
||||
* dubbo配置方式参见:https://github.com/apache/dubbo-spring-boot-project/blob/0.2.x/README_CN.md
|
||||
* <p>
|
||||
* 对比SpringCloud提供的Feign,dubbo会方便很多。
|
||||
* <p>
|
||||
* Feign的使用方式参见:com.gitee.sop.bookweb.controller.AlipayBookController#getBook2()
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
public class DubboConsumerController {
|
||||
|
||||
@Reference(version = "1.0.0", url = "dubbo://127.0.0.1:12345")
|
||||
private DemoService demoService;
|
||||
|
||||
// 作为开放接口
|
||||
@ApiMapping(value = "dubbo.story.get")
|
||||
public Story openApi(DemoParam demoParam) {
|
||||
log.info("dubbo consumer, param: {}", demoParam);
|
||||
// 通过dubbo调用story提供的服务
|
||||
DemoResult dubboStory = demoService.getStory(demoParam);
|
||||
Story story = new Story();
|
||||
story.setId(dubboStory.getId());
|
||||
story.setName(dubboStory.getName());
|
||||
return story;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
package com.gitee.sop.bookweb.param;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class BookParam {
|
||||
@ApiModelProperty(value = "图书id", example = "1")
|
||||
private int id;
|
||||
|
||||
@ApiModelProperty(value = "图书ISBN", example = "xxxx")
|
||||
private String isbn;
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
package com.gitee.sop.bookweb.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class BookVO {
|
||||
@ApiModelProperty(value = "图书id", example = "1")
|
||||
private int id;
|
||||
|
||||
@ApiModelProperty(value = "图书名称", example = "白雪公主")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "isbn", example = "xxxxxx")
|
||||
private String isbn;
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
server.port=3333
|
||||
spring.application.name=book-service
|
||||
|
||||
# nacos注册中心
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
|
||||
# consumer不需要检查provider是否启动
|
||||
dubbo.consumer.check=false
|
||||
|
||||
# zipkin服务跟踪
|
||||
#spring.zipkin.base-url=http://127.0.0.1:9411/
|
||||
## 设置sleuth收集信息的比率,默认0.1,最大是1,数字越大越耗性能
|
||||
#spring.sleuth.sampler.probability=1
|
||||
## dubbo使用zipkin过滤器
|
||||
#dubbo.provider.filter=tracing
|
||||
#dubbo.consumer.filter=tracing
|
@@ -1,17 +0,0 @@
|
||||
package com.gitee.sop.bookweb;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SopBookApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
25
sop-example/sop-easyopen/.gitignore
vendored
25
sop-example/sop-easyopen/.gitignore
vendored
@@ -1,25 +0,0 @@
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
nbproject/private/
|
||||
build/
|
||||
nbbuild/
|
||||
dist/
|
||||
nbdist/
|
||||
.nb-gradle/
|
||||
/local-config/
|
@@ -1,126 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-easyopen</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>easyopen-server</name>
|
||||
<description>easyopen Demo project for Spring Boot</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- sop接入依赖 -->
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-service-common</artifactId>
|
||||
<version>3.1.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 使用nacos注册中心
|
||||
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
|
||||
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
<version>0.2.2.RELEASE</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.oschina.durcframework</groupId>
|
||||
<artifactId>easyopen</artifactId>
|
||||
<version>1.16.1</version>
|
||||
</dependency>
|
||||
<!-- sop接入依赖 end -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<!-- 打包时跳过测试 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
@@ -1,31 +0,0 @@
|
||||
# easyopen-server
|
||||
|
||||
接口服务器空项目,可在此基础上做开发。
|
||||
|
||||
入口类:IndexController
|
||||
|
||||
业务类在api下,重点关注这里即可。
|
||||
|
||||
```
|
||||
└─com.gitee.easyopen.server
|
||||
│ EmptySpringbootApplication.java // springboot启动类
|
||||
│ IndexController.java // easyopen入口类
|
||||
│
|
||||
├─api // 存放接口
|
||||
│ │ GoodsApi.java // 示例接口
|
||||
│ │
|
||||
│ ├─param // 存放接口参数类
|
||||
│ │ GoodsParam.java
|
||||
│ │
|
||||
│ └─result // 存放放回接口类
|
||||
│ Goods.java
|
||||
│
|
||||
├─config // spring配置
|
||||
│ CorsConfig.java
|
||||
│
|
||||
├─interceptor // easyopen拦截器
|
||||
│ LogInterceptor.java
|
||||
│
|
||||
└─message // 错误处理
|
||||
CommonErrors.java
|
||||
```
|
@@ -1,25 +0,0 @@
|
||||
package com.gitee.easyopen.server;
|
||||
|
||||
import com.gitee.easyopen.ApiConfig;
|
||||
import com.gitee.easyopen.support.ApiController;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文档地址:http://localhost:8080/api/doc
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping("api")
|
||||
public class IndexController extends ApiController {
|
||||
@Override
|
||||
protected void initApiConfig(ApiConfig apiConfig) {
|
||||
apiConfig.setShowDoc(true); // 显示文档页面
|
||||
// 配置国际化消息
|
||||
Map<String, String> appSecretStore = new HashMap<String, String>();
|
||||
appSecretStore.put("test", "123456");
|
||||
apiConfig.addAppSecret(appSecretStore);
|
||||
}
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
package com.gitee.easyopen.server;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class SopEasyopenApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SopEasyopenApplication.class, args);
|
||||
}
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package com.gitee.easyopen.server.api;
|
||||
|
||||
import com.gitee.easyopen.annotation.Api;
|
||||
import com.gitee.easyopen.annotation.ApiService;
|
||||
import com.gitee.easyopen.doc.annotation.ApiDoc;
|
||||
import com.gitee.easyopen.doc.annotation.ApiDocMethod;
|
||||
import com.gitee.easyopen.server.api.param.GoodsParam;
|
||||
import com.gitee.easyopen.server.api.result.Goods;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 业务类
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@ApiService
|
||||
@ApiDoc("库存接口")
|
||||
public class Goods2Api {
|
||||
|
||||
@Api(name = "store.get")
|
||||
@ApiDocMethod(description = "获取库存")
|
||||
Goods getGoods(GoodsParam param) {
|
||||
Goods goods = new Goods();
|
||||
goods.setId(1L);
|
||||
goods.setGoods_name("苹果iPhoneX");
|
||||
goods.setPrice(new BigDecimal(8000));
|
||||
return goods;
|
||||
}
|
||||
|
||||
}
|
@@ -1,31 +0,0 @@
|
||||
package com.gitee.easyopen.server.api;
|
||||
|
||||
import com.gitee.easyopen.annotation.Api;
|
||||
import com.gitee.easyopen.annotation.ApiService;
|
||||
import com.gitee.easyopen.doc.annotation.ApiDoc;
|
||||
import com.gitee.easyopen.doc.annotation.ApiDocMethod;
|
||||
import com.gitee.easyopen.server.api.param.GoodsParam;
|
||||
import com.gitee.easyopen.server.api.result.Goods;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 业务类
|
||||
*
|
||||
* @author tanghc
|
||||
*/
|
||||
@ApiService
|
||||
@ApiDoc("商品接口")
|
||||
public class GoodsApi {
|
||||
|
||||
@Api(name = "easyopen.goods.get")
|
||||
@ApiDocMethod(description = "获取商品")
|
||||
Goods getGoods(GoodsParam param) {
|
||||
Goods goods = new Goods();
|
||||
goods.setId(1L);
|
||||
goods.setGoods_name("苹果iPhoneX");
|
||||
goods.setPrice(new BigDecimal(8000));
|
||||
return goods;
|
||||
}
|
||||
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package com.gitee.easyopen.server.api.param;
|
||||
|
||||
import com.gitee.easyopen.doc.annotation.ApiDocField;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
public class GoodsParam {
|
||||
|
||||
@ApiDocField(description = "商品名称", required = true, example = "iphoneX")
|
||||
@NotEmpty(message = "商品名称不能为空")
|
||||
@Length(min = 3, max = 20, message = "{goods.name.length}=3,20")
|
||||
private String goods_name;
|
||||
|
||||
public String getGoods_name() {
|
||||
return goods_name;
|
||||
}
|
||||
|
||||
public void setGoods_name(String goods_name) {
|
||||
this.goods_name = goods_name;
|
||||
}
|
||||
|
||||
}
|
@@ -1,46 +0,0 @@
|
||||
package com.gitee.easyopen.server.api.result;
|
||||
|
||||
import com.gitee.easyopen.doc.DataType;
|
||||
import com.gitee.easyopen.doc.annotation.ApiDocField;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class Goods {
|
||||
|
||||
@ApiDocField(description = "id")
|
||||
private Long id;
|
||||
@ApiDocField(description = "商品名称")
|
||||
private String goods_name;
|
||||
@ApiDocField(description = "价格", dataType = DataType.FLOAT)
|
||||
private BigDecimal price;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getGoods_name() {
|
||||
return goods_name;
|
||||
}
|
||||
|
||||
public void setGoods_name(String goods_name) {
|
||||
this.goods_name = goods_name;
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(BigDecimal price) {
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Goods [id=" + id + ", goods_name=" + goods_name + ", price=" + price + "]";
|
||||
}
|
||||
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
package com.gitee.easyopen.server.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* 解决js跨域
|
||||
* @author tanghc
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
/**
|
||||
* 跨域过滤器
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", buildConfig()); // 4
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
|
||||
private CorsConfiguration buildConfig() {
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.addAllowedOrigin("*");
|
||||
corsConfiguration.addAllowedHeader("*");
|
||||
corsConfiguration.addAllowedMethod("*");
|
||||
return corsConfiguration;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,28 +0,0 @@
|
||||
package com.gitee.easyopen.server.config;
|
||||
|
||||
import com.gitee.sop.servercommon.configuration.EasyopenDocSupportController;
|
||||
import com.gitee.sop.servercommon.easyopen.EasyopenServiceConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Configuration
|
||||
public class SopConfig extends EasyopenServiceConfiguration {
|
||||
|
||||
@Controller
|
||||
public static class SopDocController extends EasyopenDocSupportController {
|
||||
@Override
|
||||
public String getDocTitle() {
|
||||
return "商品API";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
//配置映射关系
|
||||
registry.addResourceHandler("/opendoc/**").addResourceLocations("classpath:/META-INF/resources/opendoc/");
|
||||
}
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
package com.gitee.easyopen.server.interceptor;
|
||||
|
||||
import com.gitee.easyopen.ApiContext;
|
||||
import com.gitee.easyopen.interceptor.ApiInterceptorAdapter;
|
||||
import com.gitee.easyopen.util.RequestUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public class LogInterceptor extends ApiInterceptorAdapter {
|
||||
|
||||
Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object serviceObj, Object argu)
|
||||
throws Exception {
|
||||
logger.info("收到客户端请求,ip={},参数={}", RequestUtil.getClientIP(request), URLDecoder.decode(ApiContext.getApiParam().toJSONString(), "UTF-8"));
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -1,16 +0,0 @@
|
||||
package com.gitee.easyopen.server.message;
|
||||
|
||||
import com.gitee.easyopen.message.ErrorMeta;
|
||||
|
||||
/**
|
||||
* 错误码放在这里
|
||||
*
|
||||
* 使用方式:throw CommonErrors.NUll_ERROR.getException();
|
||||
*/
|
||||
public interface CommonErrors {
|
||||
String isvModule = "isv.error_"; // error_zh_CN2.properties内容前缀
|
||||
|
||||
ErrorMeta NUll_ERROR = new ErrorMeta(isvModule, "200", "不能为空");
|
||||
|
||||
|
||||
}
|
@@ -1,7 +0,0 @@
|
||||
server.port=2121
|
||||
spring.application.name=easyopen-service
|
||||
|
||||
# nacos注册中心
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
|
||||
easyopen.prefix-path=/api
|
@@ -1 +0,0 @@
|
||||
spring.profiles.active=dev
|
@@ -1,2 +0,0 @@
|
||||
# common errors here
|
||||
isv.error_200=\u4E0D\u80FD\u4E3A\u7A7A
|
@@ -1,16 +0,0 @@
|
||||
package com.gitee.sop.adminserver;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SopEasyopenApplicationApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
@@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-service-common</artifactId>
|
||||
<version>3.1.5-SNAPSHOT</version>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<!-- nacos -->
|
||||
<dependency>
|
||||
|
@@ -1,15 +1,129 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.gitee.sop-story</groupId>
|
||||
<artifactId>sop-story-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.5.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-story</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>sop-story</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<modules>
|
||||
<module>sop-story-api</module>
|
||||
<module>sop-story-web</module>
|
||||
</modules>
|
||||
</project>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<!-- springboot 版本-->
|
||||
<spring-boot.version>2.2.5.RELEASE</spring-boot.version>
|
||||
<!-- spring cloud 版本 -->
|
||||
<spring-cloud.version>Hoxton.SR3</spring-cloud.version>
|
||||
<!-- spring cloud alibaba 版本 -->
|
||||
<!-- 具体版本对应关系见:https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E -->
|
||||
<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<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.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-service-common</artifactId>
|
||||
<version>3.2.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 使用nacos注册中心 -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<!-- 注册中心end -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||
<version>1.9.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 打包时跳过测试 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
25
sop-example/sop-story/sop-story-api/.gitignore
vendored
25
sop-example/sop-story/sop-story-api/.gitignore
vendored
@@ -1,25 +0,0 @@
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
@@ -1,46 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-story-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
@@ -1,18 +0,0 @@
|
||||
package com.gitee.sop.story.api.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class Story {
|
||||
private int id;
|
||||
|
||||
@NotBlank(message = "name不能为空")
|
||||
@Length(max = 20, message = "name长度不能超过20")
|
||||
private String name;
|
||||
}
|
@@ -1,14 +0,0 @@
|
||||
package com.gitee.sop.story.api.param;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* dubbo 参数
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class DemoParam implements Serializable {
|
||||
private int id;
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package com.gitee.sop.story.api.result;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* dubbo返回结果
|
||||
* @author tanghc
|
||||
*/
|
||||
@Data
|
||||
public class DemoResult implements Serializable {
|
||||
private int id;
|
||||
private String name;
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
package com.gitee.sop.story.api.service;
|
||||
|
||||
import com.gitee.sop.story.api.param.DemoParam;
|
||||
import com.gitee.sop.story.api.result.DemoResult;
|
||||
|
||||
public interface DemoService {
|
||||
|
||||
String sayHello(String name);
|
||||
|
||||
/**
|
||||
* 获取故事名称
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
DemoResult getStory(DemoParam param);
|
||||
|
||||
}
|
@@ -1,15 +0,0 @@
|
||||
package com.gitee.sop.story.api.service;
|
||||
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RequestMapping("/story")
|
||||
public interface StoryService {
|
||||
@RequestMapping("/getStory")
|
||||
Story getStory(@RequestParam("id")/* 必须指定@RequestParam,且value不能少 */
|
||||
int id);
|
||||
}
|
25
sop-example/sop-story/sop-story-web/.gitignore
vendored
25
sop-example/sop-story/sop-story-web/.gitignore
vendored
@@ -1,25 +0,0 @@
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
@@ -1,140 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-story-web</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>sop-story</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<dubbo.version>2.6.5</dubbo.version>
|
||||
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
|
||||
<!-- nacos spring cloud版本号 -->
|
||||
<spring-cloud-alibaba-nacos.version>0.9.0.RELEASE</spring-cloud-alibaba-nacos.version>
|
||||
<!-- nacos客户端版本号 -->
|
||||
<nacos-client.version>1.1.3</nacos-client.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-service-common</artifactId>
|
||||
<version>3.1.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-story-api</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 使用nacos注册中心
|
||||
版本 0.2.x.RELEASE 对应的是 Spring Boot 2.x 版本,版本 0.1.x.RELEASE 对应的是 Spring Boot 1.x 版本。
|
||||
https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-alibaba-nacos-discovery
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
<version>${spring-cloud-alibaba-nacos.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<version>${nacos-client.version}</version>
|
||||
</dependency>
|
||||
<!-- 注册中心end -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Dubbo Spring Boot Starter -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.boot</groupId>
|
||||
<artifactId>dubbo-spring-boot-starter</artifactId>
|
||||
<version>0.2.1.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>dubbo</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- swagger2 -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>swagger-bootstrap-ui</artifactId>
|
||||
<version>1.9.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- 打包时跳过测试 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/milestone</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
@@ -1,23 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import com.gitee.sop.story.api.service.StoryService;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class StoryController implements StoryService {
|
||||
|
||||
// 提供给Feign的服务
|
||||
@Override
|
||||
public Story getStory(int id) {
|
||||
Story story = new Story();
|
||||
story.setId(id);
|
||||
story.setName("海底小纵队(Feign)");
|
||||
return story;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@RestController
|
||||
public class StoryDemoController {
|
||||
|
||||
@ApiMapping(value = "story.demo.get")
|
||||
public Story getStory() {
|
||||
Story story = new Story();
|
||||
story.setId(1);
|
||||
story.setName("白雪公主");
|
||||
return story;
|
||||
}
|
||||
|
||||
}
|
@@ -1,32 +0,0 @@
|
||||
package com.gitee.sop.storyweb.service;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
import com.gitee.sop.story.api.param.DemoParam;
|
||||
import com.gitee.sop.story.api.result.DemoResult;
|
||||
import com.gitee.sop.story.api.service.DemoService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
@Service(version = "1.0.0")
|
||||
@Slf4j
|
||||
public class DefaultDemoService implements DemoService {
|
||||
|
||||
/**
|
||||
* The default value of ${dubbo.application.name} is ${spring.application.name}
|
||||
*/
|
||||
@Value("${dubbo.application.name}")
|
||||
private String serviceName;
|
||||
|
||||
public String sayHello(String name) {
|
||||
return String.format("[%s] : Hello, %s", serviceName, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DemoResult getStory(DemoParam param) {
|
||||
log.info("dubbo provider, param: {}", param);
|
||||
DemoResult demoResult = new DemoResult();
|
||||
demoResult.setId(param.getId());
|
||||
demoResult.setName("dubbo 白雪公主, param=" + param);
|
||||
return demoResult;
|
||||
}
|
||||
}
|
@@ -1 +0,0 @@
|
||||
spring.profiles.active=dev
|
@@ -6,7 +6,6 @@ import com.gitee.sop.servercommon.annotation.ApiAbility;
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.bean.OpenContext;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import com.gitee.sop.storyweb.controller.param.CategoryParam;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import com.gitee.sop.storyweb.controller.result.CategoryResult;
|
||||
@@ -291,17 +290,6 @@ public class AlipayController {
|
||||
return new TreeResult();
|
||||
}
|
||||
|
||||
// 测试参数绑定,http://localhost:2222/story/getStory4?biz_content=%7b%22id%22%3a1%2c%22name%22%3a%22aaaa%22%7d
|
||||
@ApiAbility
|
||||
@GetMapping("getStory4")
|
||||
public StoryResult getStory4(Story param, P p2) {
|
||||
System.out.println(param + ", p2=" + p2);
|
||||
StoryResult result = new StoryResult();
|
||||
result.setId(1L);
|
||||
result.setName("海底小纵队(默认版本号)" + param + ", p2=" + p2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class P {
|
||||
private String name;
|
@@ -1,7 +1,6 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@@ -1,9 +1,8 @@
|
||||
package com.gitee.sop.storyweb.controller;
|
||||
|
||||
import com.gitee.sop.servercommon.annotation.ApiMapping;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
import com.gitee.sop.servercommon.bean.OpenContext;
|
||||
import com.gitee.sop.story.api.domain.Story;
|
||||
import com.gitee.sop.servercommon.bean.ServiceContext;
|
||||
import com.gitee.sop.storyweb.controller.param.StoryParam;
|
||||
import com.gitee.sop.storyweb.controller.result.StoryResult;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -39,25 +38,4 @@ public class PostJsonController {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 演示客户端使用json方式请求(application/json)
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
@ApiMapping(value = "demo.post.json", version = "1.2")
|
||||
public Story postJson2(StoryParam param) {
|
||||
// 获取开放平台请求参数
|
||||
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
|
||||
List<Object> params = Arrays.asList(
|
||||
openContext.getAppId(),
|
||||
openContext.getMethod(),
|
||||
openContext.getVersion()
|
||||
);
|
||||
Story story = new Story();
|
||||
story.setId(1);
|
||||
story.setName("1.2 参数:" + param.getName() + ", openParams:" + StringUtils.join(params));
|
||||
return story;
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -6,13 +6,6 @@ spring.application.name=story-service
|
||||
# nacos注册中心
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
|
||||
|
||||
# dubbo配置
|
||||
dubbo.protocol.name=dubbo
|
||||
dubbo.protocol.port=12345
|
||||
dubbo.registry.address=N/A
|
||||
dubbo.scan.base-packages=com.gitee.sop.storyweb.service
|
||||
|
||||
# zipkin服务跟踪
|
||||
#spring.zipkin.base-url=http://127.0.0.1:9411/
|
||||
## 设置sleuth收集信息的比率,默认0.1,最大是1,数字越大越耗性能
|
Reference in New Issue
Block a user