From d5ef6106db6f60748fba1643d7d366f33fd58305 Mon Sep 17 00:00:00 2001 From: zhangdaiscott Date: Thu, 29 Sep 2022 10:00:37 +0800 Subject: [PATCH] =?UTF-8?q?127=20=E3=80=90=E8=BD=BB=E9=87=8F=E7=BA=A7=20PR?= =?UTF-8?q?=E3=80=91=EF=BC=9A=E4=BF=AE=E5=A4=8D=E4=BD=BF=E7=94=A8=E5=B8=A6?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E7=A9=BA=E9=97=B4=E5=90=AF=E5=8A=A8=E7=BD=91?= =?UTF-8?q?=E5=85=B3swagger=E7=9C=8B=E4=B8=8D=E5=88=B0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../swagger/MySwaggerResourceProvider.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/handler/swagger/MySwaggerResourceProvider.java b/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/handler/swagger/MySwaggerResourceProvider.java index 6c52713b..d9514d60 100644 --- a/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/handler/swagger/MySwaggerResourceProvider.java +++ b/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/handler/swagger/MySwaggerResourceProvider.java @@ -15,10 +15,7 @@ import org.springframework.stereotype.Component; import springfox.documentation.swagger.web.SwaggerResource; import springfox.documentation.swagger.web.SwaggerResourcesProvider; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * 聚合各个服务的swagger接口 @@ -44,7 +41,12 @@ public class MySwaggerResourceProvider implements SwaggerResourcesProvider { */ @Value("${spring.cloud.nacos.discovery.server-addr}") private String serverAddr; - + /** + * nacos namespace + */ + @Value("${spring.cloud.nacos.discovery.namespace}") + private String namespace; + /** * Swagger中需要排除的服务 */ @@ -107,7 +109,12 @@ public class MySwaggerResourceProvider implements SwaggerResourcesProvider { private Boolean checkRoute(String routeId) { Boolean hasRoute = false; try { - NamingService naming = NamingFactory.createNamingService(serverAddr); + //修复使用带命名空间启动网关swagger看不到接口文档的问题 + Properties properties=new Properties(); + properties.setProperty("serverAddr",serverAddr); + properties.setProperty("namespace",namespace); + NamingService naming = NamingFactory.createNamingService(properties); + List list = naming.selectInstances(routeId, true); if (ObjectUtil.isNotEmpty(list)) { hasRoute = true;