常见问题
在SpringCloudGateway中获取请求参数
微服务端如何获取appId等参数
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
String appId = openContext.getAppId();
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
Story bizObject = (Story)openContext.getBizObject();
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
Story bizObject = openContext.getBizObject(Story.class);
如何关闭签名验证
针对所有接口关闭签名验证
注册到eureka显示hostname,非ip
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
<dependency>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
参考:https://www.jianshu.com/p/5ad8317961b7
找到微服务的OpenServiceConfig.java
,重写内部类Swagger2中的swaggerAccessProtected()方法,返回false。线上请设置成true
// 开启文档
@Configuration
@EnableSwagger2
public static class Swagger2 extends SwaggerSupport {
@Override
protected String getDocTitle() {
}
@Override
return false;
}
}
调试网关出现服务不可用
参考:https://blog.csdn.net/qq_36872046/article/details/81058045
yml添加:
指定了context-path(拉取路由404)
微服务项目定义了server.servlet.context-path=/story-service
,同时必须指定:
spring.cloud.nacos.discovery.metadata.context-path=${server.servlet.context-path}
spring:
cloud:
nacos:
discovery:
metadata:
context-path: ${server.servlet.context-path}
不然网关无法拉取路由信息
在sop-gateway项目中配置
# 排除服务,多个用,隔开
sop.service.exclude=your-serviceId1,your-serviceId2
或者使用正则: