diff --git a/changelog.md b/changelog.md
index 13dd1737..edb75ef8 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,13 @@
# changelog
+## 2.5.5
+
+- 优化文档显示
+
+## 2.5.4
+
+- 可排除其它服务(`sop.service.exclude=your-serviceId1,your-serviceId2`)
+
## 2.5.3
- 修复JSR-303校验问题
diff --git a/doc/docs/_sidebar.md b/doc/docs/_sidebar.md
index 4a8a6951..d72faede 100644
--- a/doc/docs/_sidebar.md
+++ b/doc/docs/_sidebar.md
@@ -1,35 +1,35 @@
-* [首页](/?t=1573711393653)
+* [首页](/?t=1574408534264)
* 开发文档
- * [快速体验](files/10010_快速体验.md?t=1573711393655)
- * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1573711393680)
- * [新增接口](files/10020_新增接口.md?t=1573711393680)
- * [开发流程](files/10021_开发流程.md?t=1573711393680)
- * [业务参数校验](files/10030_业务参数校验.md?t=1573711393680)
- * [错误处理](files/10040_错误处理.md?t=1573711393680)
- * [编写文档](files/10041_编写文档.md?t=1573711393680)
- * [接口交互详解](files/10050_接口交互详解.md?t=1573711393680)
- * [easyopen支持](files/10070_easyopen支持.md?t=1573711393681)
- * [使用签名校验工具](files/10080_使用签名校验工具.md?t=1573711393681)
- * [ISV管理](files/10085_ISV管理.md?t=1573711393681)
- * [自定义返回结果](files/10087_自定义返回结果.md?t=1573711393681)
- * [自定义过滤器](files/10088_自定义过滤器.md?t=1573711393681)
- * [自定义校验token](files/10089_自定义校验token.md?t=1573711393681)
- * [路由授权](files/10090_路由授权.md?t=1573711393681)
- * [接口限流](files/10092_接口限流.md?t=1573711393682)
- * [监控日志](files/10093_监控日志.md?t=1573711393682)
- * [SDK开发](files/10095_SDK开发.md?t=1573711393682)
- * [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1573711393682)
- * [应用授权](files/10097_应用授权.md?t=1573711393682)
- * [提供restful接口](files/10100_提供restful接口.md?t=1573711393682)
- * [文件上传](files/10104_文件上传.md?t=1573711393682)
- * [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1573711393683)
- * [预发布灰度发布](files/10110_预发布灰度发布.md?t=1573711393683)
- * [动态修改请求参数](files/10111_动态修改请求参数.md?t=1573711393683)
- * [使用eureka](files/10112_使用eureka.md?t=1573711393683)
- * [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1573711393683)
+ * [快速体验](files/10010_快速体验.md?t=1574408534265)
+ * [项目接入到SOP](files/10011_项目接入到SOP.md?t=1574408534281)
+ * [新增接口](files/10020_新增接口.md?t=1574408534281)
+ * [开发流程](files/10021_开发流程.md?t=1574408534281)
+ * [业务参数校验](files/10030_业务参数校验.md?t=1574408534281)
+ * [错误处理](files/10040_错误处理.md?t=1574408534281)
+ * [编写文档](files/10041_编写文档.md?t=1574408534282)
+ * [接口交互详解](files/10050_接口交互详解.md?t=1574408534282)
+ * [easyopen支持](files/10070_easyopen支持.md?t=1574408534282)
+ * [使用签名校验工具](files/10080_使用签名校验工具.md?t=1574408534282)
+ * [ISV管理](files/10085_ISV管理.md?t=1574408534282)
+ * [自定义返回结果](files/10087_自定义返回结果.md?t=1574408534282)
+ * [自定义过滤器](files/10088_自定义过滤器.md?t=1574408534282)
+ * [自定义校验token](files/10089_自定义校验token.md?t=1574408534282)
+ * [路由授权](files/10090_路由授权.md?t=1574408534282)
+ * [接口限流](files/10092_接口限流.md?t=1574408534282)
+ * [监控日志](files/10093_监控日志.md?t=1574408534282)
+ * [SDK开发](files/10095_SDK开发.md?t=1574408534283)
+ * [使用SpringCloudGateway](files/10096_使用SpringCloudGateway.md?t=1574408534283)
+ * [应用授权](files/10097_应用授权.md?t=1574408534283)
+ * [提供restful接口](files/10100_提供restful接口.md?t=1574408534283)
+ * [文件上传](files/10104_文件上传.md?t=1574408534283)
+ * [配置Sleuth链路追踪](files/10109_配置Sleuth链路追踪.md?t=1574408534283)
+ * [预发布灰度发布](files/10110_预发布灰度发布.md?t=1574408534283)
+ * [动态修改请求参数](files/10111_动态修改请求参数.md?t=1574408534283)
+ * [使用eureka](files/10112_使用eureka.md?t=1574408534283)
+ * [扩展其它注册中心](files/10113_扩展其它注册中心.md?t=1574408534283)
* 原理分析
- * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1573711393683)
- * [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1573711393683)
- * [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1573711393683)
- * [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1573711393684)
- * [常见问题](files/90100_常见问题.md?t=1573711393684)
+ * [原理分析之@ApiMapping](files/90010_原理分析之@ApiMapping.md?t=1574408534283)
+ * [原理分析之如何存储路由](files/90011_原理分析之如何存储路由.md?t=1574408534283)
+ * [原理分析之如何路由](files/90012_原理分析之如何路由.md?t=1574408534283)
+ * [原理分析之文档归纳](files/90013_原理分析之文档归纳.md?t=1574408534284)
+ * [常见问题](files/90100_常见问题.md?t=1574408534284)
diff --git a/doc/docs/files/90100_常见问题.md b/doc/docs/files/90100_常见问题.md
index 0a970c6f..67eb4f8b 100644
--- a/doc/docs/files/90100_常见问题.md
+++ b/doc/docs/files/90100_常见问题.md
@@ -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\\-.*
+```
diff --git a/sop-auth/pom.xml b/sop-auth/pom.xml
index 460e66de..66b23fbd 100644
--- a/sop-auth/pom.xml
+++ b/sop-auth/pom.xml
@@ -26,7 +26,7 @@
com.gitee.sop
sop-service-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
diff --git a/sop-common/pom.xml b/sop-common/pom.xml
index fcfa286f..3e8e634c 100644
--- a/sop-common/pom.xml
+++ b/sop-common/pom.xml
@@ -5,7 +5,7 @@
4.0.0
com.gitee.sop
sop-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
pom
diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml
index b975cb4e..c8f6c86a 100644
--- a/sop-common/sop-gateway-common/pom.xml
+++ b/sop-common/sop-gateway-common/pom.xml
@@ -5,11 +5,11 @@
com.gitee.sop
sop-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
../pom.xml
sop-gateway-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
jar
sop-gateway-common
@@ -83,6 +83,13 @@
2.3.0
true
+
+
+ junit
+ junit
+ 4.12
+ test
+
diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java
index d4c7856c..54a2fd60 100644
--- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java
+++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/bean/SopConstants.java
@@ -22,6 +22,8 @@ public class SopConstants {
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);
diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java
index 3590c040..f05fa2eb 100644
--- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java
+++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/EnvironmentKeys.java
@@ -26,7 +26,17 @@ public enum EnvironmentKeys {
/**
* 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 defaultValue;
diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java
index c80158fd..1391bfa7 100644
--- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java
+++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/ServiceRoutesLoader.java
@@ -9,6 +9,7 @@ import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.api.naming.pojo.ServiceInfo;
import com.gitee.sop.gatewaycommon.bean.NacosConfigs;
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.route.RegistryListener;
import lombok.extern.slf4j.Slf4j;
@@ -46,8 +47,6 @@ public class ServiceRoutesLoader {
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";
@Autowired
@@ -159,7 +158,7 @@ public class ServiceRoutesLoader {
} else {
// 默认处理
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;
}
if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) {
diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java
index 5fc35061..4167e93b 100644
--- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java
+++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/BaseRegistryListener.java
@@ -1,10 +1,13 @@
package com.gitee.sop.gatewaycommon.route;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
+import com.gitee.sop.gatewaycommon.manager.EnvironmentKeys;
import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -50,10 +53,9 @@ public abstract class BaseRegistryListener implements RegistryListener {
}
protected boolean canOperator(String serviceId) {
- for (String excludeServiceId : EXCLUDE_SERVICE_ID_LIST) {
- if (excludeServiceId.equalsIgnoreCase(serviceId)) {
- return false;
- }
+ // 被排除的服务,不能操作
+ if (isExcludeService(serviceId)) {
+ return false;
}
// nacos会不停的触发事件,这里做了一层拦截
// 同一个serviceId5秒内允许访问一次
@@ -65,4 +67,43 @@ public abstract class BaseRegistryListener implements RegistryListener {
}
return can;
}
+
+ /**
+ * 是否是被排除的服务
+ *
+ * @param serviceId 服务id
+ * @return true,是
+ */
+ private boolean isExcludeService(String serviceId) {
+ List 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 getExcludeServiceId() {
+ String excludeServiceIds = EnvironmentKeys.SOP_SERVICE_EXCLUDE.getValue();
+ List 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;
+ }
+
+
}
diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java
index 3a0f81d9..5c7b0a80 100644
--- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java
+++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/route/ServiceRouteListener.java
@@ -3,6 +3,7 @@ package com.gitee.sop.gatewaycommon.route;
import com.alibaba.fastjson.JSON;
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
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.EnvironmentKeys;
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 METADATA_SERVER_CONTEXT_PATH = "server.servlet.context-path";
-
private static final String METADATA_SOP_ROUTES_PATH = "sop.routes.path";
private static final String HEADER_RESTFUL = "restful";
@@ -89,7 +88,7 @@ public class ServiceRouteListener extends BaseServiceListener {
} else {
// 默认处理
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;
}
if (StringUtils.isNotBlank(servletPath) && !servletPath.startsWith("/")) {
diff --git a/sop-common/sop-gateway-common/src/test/java/com/gitee/sop/gatewaycommon/ExcludeTest.java b/sop-common/sop-gateway-common/src/test/java/com/gitee/sop/gatewaycommon/ExcludeTest.java
new file mode 100644
index 00000000..0d7f7b2d
--- /dev/null
+++ b/sop-common/sop-gateway-common/src/test/java/com/gitee/sop/gatewaycommon/ExcludeTest.java
@@ -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");
+ }
+ }
+ }
+ }
+}
diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml
index 4dd0236b..747d9757 100644
--- a/sop-common/sop-service-common/pom.xml
+++ b/sop-common/sop-service-common/pom.xml
@@ -6,11 +6,11 @@
com.gitee.sop
sop-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
../pom.xml
sop-service-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
jar
sop-service-common
diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java
index 93efe8ea..a71bf45b 100644
--- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java
+++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/OpenContextImpl.java
@@ -39,6 +39,8 @@ public class OpenContextImpl implements OpenContext {
String bizContent = getBizContent();
if (bizContent != null) {
bizObject = (T) JSON.parseObject(bizContent, bizClass);
+ } else {
+ bizObject = (T) rootJsonObject.toJavaObject(bizClass);
}
}
}
diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
index 506704b6..8506f015 100644
--- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
+++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java
@@ -17,19 +17,6 @@ import java.lang.reflect.Method;
*/
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
protected RequestCondition> getCustomMethodCondition(Method method) {
method.setAccessible(true);
diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml
index 79b64a77..3b963552 100644
--- a/sop-example/sop-book/sop-book-web/pom.xml
+++ b/sop-example/sop-book/sop-book-web/pom.xml
@@ -28,7 +28,7 @@
com.gitee.sop
sop-service-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
com.gitee.sop
diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml
index 8ae007c9..71ffdf9c 100644
--- a/sop-example/sop-easyopen/pom.xml
+++ b/sop-example/sop-easyopen/pom.xml
@@ -29,7 +29,7 @@
com.gitee.sop
sop-service-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
@@ -91,6 +91,18 @@
1.2.17
+
+
+ io.springfox
+ springfox-swagger2
+ 2.9.2
+
+
+ com.github.xiaoymin
+ swagger-bootstrap-ui
+ 1.9.5
+
+
diff --git a/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/Swagger2.java b/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/Swagger2.java
new file mode 100644
index 00000000..d09fd292
--- /dev/null
+++ b/sop-example/sop-springmvc/src/main/java/com/gitee/app/config/Swagger2.java
@@ -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;
+ }
+}
\ No newline at end of file
diff --git a/sop-example/sop-springmvc/src/main/java/com/gitee/app/HomeController.java b/sop-example/sop-springmvc/src/main/java/com/gitee/app/controller/HomeController.java
similarity index 87%
rename from sop-example/sop-springmvc/src/main/java/com/gitee/app/HomeController.java
rename to sop-example/sop-springmvc/src/main/java/com/gitee/app/controller/HomeController.java
index 04a5d638..7028c51b 100644
--- a/sop-example/sop-springmvc/src/main/java/com/gitee/app/HomeController.java
+++ b/sop-example/sop-springmvc/src/main/java/com/gitee/app/controller/HomeController.java
@@ -1,7 +1,9 @@
-package com.gitee.app;
+package com.gitee.app.controller;
import com.gitee.app.model.Goods;
import com.gitee.sop.servercommon.annotation.ApiMapping;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
@@ -18,6 +20,7 @@ import java.util.Locale;
/**
* Handles requests for the application home page.
*/
+@Api(tags = "MVC接口")
@Controller
public class HomeController {
@@ -41,6 +44,7 @@ public class HomeController {
}
+ @ApiOperation(value="获取商品", notes = "获取商品说明")
@ApiMapping(value = "springmvc.goods.get")
@ResponseBody
public Goods getGoods(Goods param) {
diff --git a/sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml b/sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
index 2956e9bb..e27b63be 100644
--- a/sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
+++ b/sop-example/sop-springmvc/src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml
@@ -34,6 +34,11 @@
+
+
+
+
+
diff --git a/sop-example/sop-springmvc/src/main/webapp/WEB-INF/web.xml b/sop-example/sop-springmvc/src/main/webapp/WEB-INF/web.xml
index b7dfa271..630564eb 100644
--- a/sop-example/sop-springmvc/src/main/webapp/WEB-INF/web.xml
+++ b/sop-example/sop-springmvc/src/main/webapp/WEB-INF/web.xml
@@ -29,6 +29,29 @@
1
+
+
+
+ appServlet
+ /v2/api-docs
+
+
+ appServlet
+ /swagger-resources
+
+
+ appServlet
+ /swagger-resources/configuration/ui
+
+
+ appServlet
+ /swagger-resources/configuration/security
+
+
+
+ appServlet
+ /v2/api-docs-ext
+
appServlet
diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml
index 4e5ce0f3..d0ea4606 100644
--- a/sop-example/sop-story/sop-story-web/pom.xml
+++ b/sop-example/sop-story/sop-story-web/pom.xml
@@ -28,7 +28,7 @@
com.gitee.sop
sop-service-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
com.gitee.sop
diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml
index 3d191568..1fa42884 100644
--- a/sop-gateway/pom.xml
+++ b/sop-gateway/pom.xml
@@ -29,7 +29,7 @@
com.gitee.sop
sop-gateway-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
diff --git a/sop-website/pom.xml b/sop-website/pom.xml
index e5ea4a64..c496a577 100644
--- a/sop-website/pom.xml
+++ b/sop-website/pom.xml
@@ -35,7 +35,7 @@
com.gitee.sop
sop-gateway-common
- 2.5.3-SNAPSHOT
+ 2.5.5-SNAPSHOT
diff --git a/sop-website/src/main/java/com/gitee/sop/websiteserver/config/WebsiteConfig.java b/sop-website/src/main/java/com/gitee/sop/websiteserver/config/WebsiteConfig.java
index 335e0efb..0142a941 100644
--- a/sop-website/src/main/java/com/gitee/sop/websiteserver/config/WebsiteConfig.java
+++ b/sop-website/src/main/java/com/gitee/sop/websiteserver/config/WebsiteConfig.java
@@ -3,6 +3,7 @@ package com.gitee.sop.websiteserver.config;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
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.NacosRegistryListener;
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.Configuration;
import org.springframework.context.event.EventListener;
+import org.springframework.core.env.Environment;
+
+import javax.annotation.PostConstruct;
/**
* @author tanghc
@@ -33,6 +37,9 @@ public class WebsiteConfig implements ApplicationRunner {
@Autowired
private RegistryListener registryListener;
+ @Autowired
+ private Environment environment;
+
/**
* 使用fastjson代替jackson
* @return
@@ -84,6 +91,11 @@ public class WebsiteConfig implements ApplicationRunner {
*/
@Override
public void run(ApplicationArguments args) throws Exception {
-// docManager.load(null);
+
+ }
+
+ @PostConstruct
+ public void after() {
+ EnvironmentContext.setEnvironment(environment);
}
}
diff --git a/sop-website/src/main/java/com/gitee/sop/websiteserver/listener/ServiceDocListener.java b/sop-website/src/main/java/com/gitee/sop/websiteserver/listener/ServiceDocListener.java
index dd3eed10..9583c7c7 100644
--- a/sop-website/src/main/java/com/gitee/sop/websiteserver/listener/ServiceDocListener.java
+++ b/sop-website/src/main/java/com/gitee/sop/websiteserver/listener/ServiceDocListener.java
@@ -1,6 +1,7 @@
package com.gitee.sop.websiteserver.listener;
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.websiteserver.manager.DocManager;
import lombok.extern.slf4j.Slf4j;
@@ -45,6 +46,7 @@ public class ServiceDocListener extends BaseServiceListener {
private static String getRouteRequestUrl(InstanceDefinition instance) {
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;
}
}