Merge branch 'master' into eureka

eureka
tanghc 5 years ago
commit 147fd67c96
  1. 8
      changelog.md
  2. 66
      doc/docs/_sidebar.md
  3. 17
      doc/docs/files/90100_常见问题.md
  4. 2
      sop-auth/pom.xml
  5. 2
      sop-common/pom.xml
  6. 11
      sop-common/sop-gateway-common/pom.xml
  7. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java
  8. 12
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java
  9. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java
  10. 49
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java
  11. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java
  12. 22
      sop-common/sop-gateway-common/src/test/java/com/gitee/sop/gatewaycommon/ExcludeTest.java
  13. 4
      sop-common/sop-service-common/pom.xml
  14. 2
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java
  15. 13
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
  16. 2
      sop-example/sop-book/sop-book-web/pom.xml
  17. 2
      sop-example/sop-easyopen/pom.xml
  18. 14
      sop-example/sop-springmvc/pom.xml
  19. 21
      sop-example/sop-springmvc/src/main/java/com/gitee/app/config/Swagger2.java
  20. 6
      sop-example/sop-springmvc/src/main/java/com/gitee/app/controller/HomeController.java
  21. 5
      sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
  22. 23
      sop-example/sop-springmvc/src/main/webapp/WEB-INF/web.xml
  23. 2
      sop-example/sop-story/sop-story-web/pom.xml
  24. 2
      sop-gateway/pom.xml
  25. 2
      sop-website/pom.xml
  26. 14
      sop-website/src/main/java/com/gitee/sop/websiteserver/config/WebsiteConfig.java
  27. 4
      sop-website/src/main/java/com/gitee/sop/websiteserver/listener/ServiceDocListener.java

@ -1,5 +1,13 @@
# changelog # changelog
## 2.5.5
- 优化文档显示
## 2.5.4
- 可排除其它服务(`sop.service.exclude=your-serviceId1,your-serviceId2`)
## 2.5.3 ## 2.5.3
- 修复JSR-303校验问题 - 修复JSR-303校验问题

@ -1,35 +1,35 @@
* [首页](/?t=1573711393653) * [首页](/?t=1574408534264)
* 开发文档 * 开发文档
* [快速体验](files/10010_快速体验.md?t=1573711393655) * [快速体验](files/10010_快速体验.md?t=1574408534265)
* [项目接入到SOP](files/10011_项目接入到SOP.md?t=1573711393680) * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1574408534281)
* [新增接口](files/10020_新增接口.md?t=1573711393680) * [新增接口](files/10020_新增接口.md?t=1574408534281)
* [开发流程](files/10021_开发流程.md?t=1573711393680) * [开发流程](files/10021_开发流程.md?t=1574408534281)
* [业务参数校验](files/10030_业务参数校验.md?t=1573711393680) * [业务参数校验](files/10030_业务参数校验.md?t=1574408534281)
* [错误处理](files/10040_错误处理.md?t=1573711393680) * [错误处理](files/10040_错误处理.md?t=1574408534281)
* [编写文档](files/10041_编写文档.md?t=1573711393680) * [编写文档](files/10041_编写文档.md?t=1574408534282)
* [接口交互详解](files/10050_接口交互详解.md?t=1573711393680) * [接口交互详解](files/10050_接口交互详解.md?t=1574408534282)
* [easyopen支持](files/10070_easyopen支持.md?t=1573711393681) * [easyopen支持](files/10070_easyopen支持.md?t=1574408534282)
* [使用签名校验工具](files/10080_使用签名校验工具.md?t=1573711393681) * [使用签名校验工具](files/10080_使用签名校验工具.md?t=1574408534282)
* [ISV管理](files/10085_ISV管理.md?t=1573711393681) * [ISV管理](files/10085_ISV管理.md?t=1574408534282)
* [自定义返回结果](files/10087_自定义返回结果.md?t=1573711393681) * [自定义返回结果](files/10087_自定义返回结果.md?t=1574408534282)
* [自定义过滤器](files/10088_自定义过滤器.md?t=1573711393681) * [自定义过滤器](files/10088_自定义过滤器.md?t=1574408534282)
* [自定义校验token](files/10089_自定义校验token.md?t=1573711393681) * [自定义校验token](files/10089_自定义校验token.md?t=1574408534282)
* [路由授权](files/10090_路由授权.md?t=1573711393681) * [路由授权](files/10090_路由授权.md?t=1574408534282)
* [接口限流](files/10092_接口限流.md?t=1573711393682) * [接口限流](files/10092_接口限流.md?t=1574408534282)
* [监控日志](files/10093_监控日志.md?t=1573711393682) * [监控日志](files/10093_监控日志.md?t=1574408534282)
* [SDK开发](files/10095_SDK开发.md?t=1573711393682) * [SDK开发](files/10095_SDK开发.md?t=1574408534283)
* [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1573711393682) * [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1574408534283)
* [应用授权](files/10097_应用授权.md?t=1573711393682) * [应用授权](files/10097_应用授权.md?t=1574408534283)
* [提供restful接口](files/10100_提供restful接口.md?t=1573711393682) * [提供restful接口](files/10100_提供restful接口.md?t=1574408534283)
* [文件上传](files/10104_文件上传.md?t=1573711393682) * [文件上传](files/10104_文件上传.md?t=1574408534283)
* [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1573711393683) * [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1574408534283)
* [预发布灰度发布](files/10110_预发布灰度发布.md?t=1573711393683) * [预发布灰度发布](files/10110_预发布灰度发布.md?t=1574408534283)
* [动态修改请求参数](files/10111_动态修改请求参数.md?t=1573711393683) * [动态修改请求参数](files/10111_动态修改请求参数.md?t=1574408534283)
* [使用eureka](files/10112_使用eureka.md?t=1573711393683) * [使用eureka](files/10112_使用eureka.md?t=1574408534283)
* [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1573711393683) * [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1574408534283)
* 原理分析 * 原理分析
* [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1573711393683) * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1574408534283)
* [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1573711393683) * [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1574408534283)
* [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1573711393683) * [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1574408534283)
* [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1573711393684) * [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1574408534284)
* [常见问题](files/90100_常见问题.md?t=1573711393684) * [常见问题](files/90100_常见问题.md?t=1574408534284)

@ -112,3 +112,20 @@ spring.cloud.nacos.discovery.metadata.server.servlet.context-path=${server.servl
``` ```
不然网关无法拉取路由信息 不然网关无法拉取路由信息
## 其它微服务没有开放接口,需要排除
在sop-gateway项目中配置
```properties
# 排除服务,多个用,隔开
sop.service.exclude=your-serviceId1,your-serviceId2
```
或者使用正则:
```properties
# 排除以"test-"开头的
# 多个正则用英文分号(;)隔开
sop.service.exclude-regex=test\\-.*
```

@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
</dependency> </dependency>
<!-- sop相关配置 end--> <!-- sop相关配置 end-->

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>

@ -5,11 +5,11 @@
<parent> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-gateway-common</name> <name>sop-gateway-common</name>
@ -83,6 +83,13 @@
<version>2.3.0</version> <version>2.3.0</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>

@ -22,6 +22,8 @@ public class SopConstants {
public static final String REDIRECT_PATH_KEY = "r-path"; public static final String REDIRECT_PATH_KEY = "r-path";
public static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path";
/** /**
* 在拦截器中调用获取参数 * 在拦截器中调用获取参数
* String cachedBody = (String)exchange.getAttribute(SopConstants.CACHE_REQUEST_BODY_OBJECT_KEY); * String cachedBody = (String)exchange.getAttribute(SopConstants.CACHE_REQUEST_BODY_OBJECT_KEY);

@ -26,7 +26,17 @@ public enum EnvironmentKeys {
/** /**
* sop.restful.path=/xx 指定请求前缀默认/rest * sop.restful.path=/xx 指定请求前缀默认/rest
*/ */
SOP_RESTFUL_PATH("sop.restful.path", "/rest"); SOP_RESTFUL_PATH("sop.restful.path", "/rest"),
/**
* 排除其它微服务多个用英文逗号隔开
*/
SOP_SERVICE_EXCLUDE("sop.service.exclude"),
/**
* 排除其它微服务正则形式多个用英文逗号隔开
*/
SOP_SERVICE_EXCLUDE_REGEX("sop.service.exclude-regex")
;
private String key; private String key;
private String defaultValue; private String defaultValue;

@ -9,6 +9,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo; import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.gitee.sop.gatewaycommon.bean.NacosConfigs; import com.gitee.sop.gatewaycommon.bean.NacosConfigs;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo; import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.bean.TargetRoute; import com.gitee.sop.gatewaycommon.bean.TargetRoute;
import com.gitee.sop.gatewaycommon.route.RegistryListener; import com.gitee.sop.gatewaycommon.route.RegistryListener;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -46,8 +47,6 @@ public class ServiceRoutesLoader<T extends TargetRoute> {
private static final int FIVE_SECONDS = 1000 * 5; private static final int FIVE_SECONDS = 1000 * 5;
private static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path";
private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path"; private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path";
@Autowired @Autowired
@ -159,7 +158,7 @@ public class ServiceRoutesLoader<T extends TargetRoute> {
} else { } else {
// 默认处理 // 默认处理
homeUrl = getHomeUrl(instance); homeUrl = getHomeUrl(instance);
String contextPath = metadata.getOrDefault(METADATA_SERVER_CONTEXT_PATH, ""); String contextPath = metadata.getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, "");
servletPath = contextPath + SOP_ROUTES_PATH; servletPath = contextPath + SOP_ROUTES_PATH;
} }
if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) { if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) {

@ -1,10 +1,13 @@
package com.gitee.sop.gatewaycommon.route; package com.gitee.sop.gatewaycommon.route;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
import com.gitee.sop.gatewaycommon.manager.EnvironmentKeys;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -50,10 +53,9 @@ public abstract class BaseRegistryListener implements RegistryListener {
} }
protected boolean canOperator(String serviceId) { protected boolean canOperator(String serviceId) {
for (String excludeServiceId : EXCLUDE_SERVICE_ID_LIST) { // 被排除的服务,不能操作
if (excludeServiceId.equalsIgnoreCase(serviceId)) { if (isExcludeService(serviceId)) {
return false; return false;
}
} }
// nacos会不停的触发事件,这里做了一层拦截 // nacos会不停的触发事件,这里做了一层拦截
// 同一个serviceId5秒内允许访问一次 // 同一个serviceId5秒内允许访问一次
@ -65,4 +67,43 @@ public abstract class BaseRegistryListener implements RegistryListener {
} }
return can; return can;
} }
/**
* 是否是被排除的服务
*
* @param serviceId 服务id
* @return true
*/
private boolean isExcludeService(String serviceId) {
List<String> excludeServiceIdList = getExcludeServiceId();
for (String excludeServiceId : excludeServiceIdList) {
if (excludeServiceId.equalsIgnoreCase(serviceId)) {
return true;
}
}
// 匹配正则
String sopServiceExcludeRegex = EnvironmentKeys.SOP_SERVICE_EXCLUDE_REGEX.getValue();
if (StringUtils.isNotBlank(sopServiceExcludeRegex)) {
String[] regexArr = sopServiceExcludeRegex.split(";");
for (String regex : regexArr) {
if (serviceId.matches(regex)) {
return true;
}
}
}
return false;
}
private List<String> getExcludeServiceId() {
String excludeServiceIds = EnvironmentKeys.SOP_SERVICE_EXCLUDE.getValue();
List<String> excludeServiceIdList = new ArrayList<>(8);
if (StringUtils.isNotBlank(excludeServiceIds)) {
String[] serviceIdArr = excludeServiceIds.split(",");
excludeServiceIdList.addAll(Arrays.asList(serviceIdArr));
}
excludeServiceIdList.addAll(EXCLUDE_SERVICE_ID_LIST);
return excludeServiceIdList;
}
} }

@ -3,6 +3,7 @@ package com.gitee.sop.gatewaycommon.route;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo; import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.manager.BaseRouteCache; import com.gitee.sop.gatewaycommon.manager.BaseRouteCache;
import com.gitee.sop.gatewaycommon.manager.EnvironmentKeys; import com.gitee.sop.gatewaycommon.manager.EnvironmentKeys;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -23,8 +24,6 @@ public class ServiceRouteListener extends BaseServiceListener {
private static final String SOP_ROUTES_PATH = "/sop/routes"; private static final String SOP_ROUTES_PATH = "/sop/routes";
private static final String METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path";
private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path"; private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path";
private static final String HEADER_RESTFUL = "restful"; private static final String HEADER_RESTFUL = "restful";
@ -89,7 +88,7 @@ public class ServiceRouteListener extends BaseServiceListener {
} else { } else {
// 默认处理 // 默认处理
homeUrl = getHomeUrl(instance); homeUrl = getHomeUrl(instance);
String contextPath = metadata.getOrDefault(METADATA_SERVER_CONTEXT_PATH, ""); String contextPath = metadata.getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, "");
servletPath = contextPath + SOP_ROUTES_PATH; servletPath = contextPath + SOP_ROUTES_PATH;
} }
if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) { if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) {

@ -0,0 +1,22 @@
package com.gitee.sop.gatewaycommon;
import junit.framework.TestCase;
import org.apache.commons.lang.StringUtils;
/**
* @author tanghc
*/
public class ExcludeTest extends TestCase {
public void testRegex() {
String serviceId = "com.aaa.bbb.story-service";
String sopServiceExcludeRegex = "com\\..*;story\\-.*";
if (StringUtils.isNotBlank(sopServiceExcludeRegex)) {
String[] regexArr = sopServiceExcludeRegex.split(";");
for (String regex : regexArr) {
if (serviceId.matches(regex)) {
System.out.println("111");
}
}
}
}
}

@ -6,11 +6,11 @@
<parent> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-service-common</name> <name>sop-service-common</name>

@ -39,6 +39,8 @@ public class OpenContextImpl<T> implements OpenContext<T> {
String bizContent = getBizContent(); String bizContent = getBizContent();
if (bizContent != null) { if (bizContent != null) {
bizObject = (T) JSON.parseObject(bizContent, bizClass); bizObject = (T) JSON.parseObject(bizContent, bizClass);
} else {
bizObject = (T) rootJsonObject.toJavaObject(bizClass);
} }
} }
} }

@ -17,19 +17,6 @@ import java.lang.reflect.Method;
*/ */
public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping implements PriorityOrdered { public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping implements PriorityOrdered {
private static StringValueResolver stringValueResolver = new ApiMappingStringValueResolver();
@Override
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
ApiMapping apiMapping = method.getAnnotation(ApiMapping.class);
StringValueResolver valueResolver = null;
if (apiMapping != null) {
valueResolver = stringValueResolver;
}
this.setEmbeddedValueResolver(valueResolver);
return super.getMappingForMethod(method, handlerType);
}
@Override @Override
protected RequestCondition<?> getCustomMethodCondition(Method method) { protected RequestCondition<?> getCustomMethodCondition(Method method) {
method.setAccessible(true); method.setAccessible(true);

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
</dependency> </dependency>
<!-- 使用nacos注册中心 <!-- 使用nacos注册中心

@ -20,7 +20,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
</dependency> </dependency>
<!-- nacos --> <!-- nacos -->
<dependency> <dependency>
@ -91,6 +91,18 @@
<version>1.2.17</version> <version>1.2.17</version>
</dependency> </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>
<!-- @Inject --> <!-- @Inject -->
<dependency> <dependency>

@ -0,0 +1,21 @@
package com.gitee.app.config;
import com.gitee.sop.servercommon.swagger.SwaggerSupport;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
* 开启文档本地微服务文档地址http://localhost:2222/doc.html
* http://ip:port/v2/api-docs
*/
@EnableSwagger2
public class Swagger2 extends SwaggerSupport {
@Override
protected String getDocTitle() {
return "MVC_API";
}
@Override
protected boolean swaggerAccessProtected() {
return false;
}
}

@ -1,7 +1,9 @@
package com.gitee.app; package com.gitee.app.controller;
import com.gitee.app.model.Goods; import com.gitee.app.model.Goods;
import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.servercommon.annotation.ApiMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -18,6 +20,7 @@ import java.util.Locale;
/** /**
* Handles requests for the application home page. * Handles requests for the application home page.
*/ */
@Api(tags = "MVC接口")
@Controller @Controller
public class HomeController { public class HomeController {
@ -41,6 +44,7 @@ public class HomeController {
} }
@ApiOperation(value="获取商品", notes = "获取商品说明")
@ApiMapping(value = "springmvc.goods.get") @ApiMapping(value = "springmvc.goods.get")
@ResponseBody @ResponseBody
public Goods getGoods(Goods param) { public Goods getGoods(Goods param) {

@ -34,6 +34,11 @@
</mvc:annotation-driven> </mvc:annotation-driven>
<bean class="com.gitee.app.config.OpenServiceConfig"/> <bean class="com.gitee.app.config.OpenServiceConfig"/>
<!-- swagger2 配置 -->
<mvc:resources location="classpath:/META-INF/resources/" mapping="doc.html"/>
<mvc:resources location="classpath:/META-INF/resources/webjars/" mapping="/webjars/**"/>
<bean class="com.gitee.app.config.Swagger2"/>
<!-- 接入SOP配置 end --> <!-- 接入SOP配置 end -->
</beans> </beans>

@ -29,6 +29,29 @@
</init-param> </init-param>
<load-on-startup>1</load-on-startup> <load-on-startup>1</load-on-startup>
</servlet> </servlet>
<!-- 配置swagger-bootstrap-ui的url请求路径-->
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/v2/api-docs</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/swagger-resources</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/swagger-resources/configuration/ui</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/swagger-resources/configuration/security</url-pattern>
</servlet-mapping>
<!--此接口地址为SwaggerBootstrapUi提供的增强地址,如果不使用增强功能,可排除此配置-->
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/v2/api-docs-ext</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>appServlet</servlet-name> <servlet-name>appServlet</servlet-name>

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
</dependency> </dependency>
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ --> <!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->

@ -35,7 +35,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.3-SNAPSHOT</version> <version>2.5.5-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

@ -3,6 +3,7 @@ package com.gitee.sop.websiteserver.config;
import com.alibaba.fastjson.serializer.SerializerFeature; import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig; import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.gitee.sop.gatewaycommon.manager.EnvironmentContext;
import com.gitee.sop.gatewaycommon.route.EurekaRegistryListener; import com.gitee.sop.gatewaycommon.route.EurekaRegistryListener;
import com.gitee.sop.gatewaycommon.route.NacosRegistryListener; import com.gitee.sop.gatewaycommon.route.NacosRegistryListener;
import com.gitee.sop.gatewaycommon.route.RegistryListener; import com.gitee.sop.gatewaycommon.route.RegistryListener;
@ -20,6 +21,9 @@ import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.core.env.Environment;
import javax.annotation.PostConstruct;
/** /**
* @author tanghc * @author tanghc
@ -33,6 +37,9 @@ public class WebsiteConfig implements ApplicationRunner {
@Autowired @Autowired
private RegistryListener registryListener; private RegistryListener registryListener;
@Autowired
private Environment environment;
/** /**
* 使用fastjson代替jackson * 使用fastjson代替jackson
* @return * @return
@ -84,6 +91,11 @@ public class WebsiteConfig implements ApplicationRunner {
*/ */
@Override @Override
public void run(ApplicationArguments args) throws Exception { public void run(ApplicationArguments args) throws Exception {
// docManager.load(null);
}
@PostConstruct
public void after() {
EnvironmentContext.setEnvironment(environment);
} }
} }

@ -1,6 +1,7 @@
package com.gitee.sop.websiteserver.listener; package com.gitee.sop.websiteserver.listener;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition; import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.route.BaseServiceListener; import com.gitee.sop.gatewaycommon.route.BaseServiceListener;
import com.gitee.sop.websiteserver.manager.DocManager; import com.gitee.sop.websiteserver.manager.DocManager;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -45,6 +46,7 @@ public class ServiceDocListener extends BaseServiceListener {
private static String getRouteRequestUrl(InstanceDefinition instance) { private static String getRouteRequestUrl(InstanceDefinition instance) {
String query = buildQuery(SECRET); String query = buildQuery(SECRET);
return "http://" + instance.getIp() + ":" + instance.getPort() + "/v2/api-docs" + query; String contextPath = instance.getMetadata().getOrDefault(SopConstants.METADATA_SERVER_CONTEXT_PATH, "");
return "http://" + instance.getIp() + ":" + instance.getPort() + contextPath + "/v2/api-docs" + query;
} }
} }

Loading…
Cancel
Save