Files
SOP/doc/docs/files/90100_常见问题.md
tanghc 36ee797ea6 2.0.0
2019-09-04 09:43:42 +08:00

104 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 常见问题
## 在zuul过滤器中获取请求参数
```java
ApiParam param = ZuulContext.getApiParam();
```
## 在SpringCloudGateway中获取请求参数
```java
ApiParam apiParam = ServerWebExchangeUtil.getApiParam(exchange);
```
## 微服务端如何获取appId等参数
```java
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
String appId = openContext.getAppId();
```
## 在其它地方获取业务参数
```java
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
Story bizObject = (Story)openContext.getBizObject();
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
Story bizObject = openContext.getBizObject(Story.class);
```
## 如何关闭签名验证
- 针对某一个接口关闭签名验证
`@ApiMapping(value = "alipay.story.get", ignoreValidate = true)`
- 针对所有接口关闭签名验证
```java
@Configuration
public class ZuulConfig extends AlipayZuulConfiguration {
static {
...
ApiConfig.getInstance().setIgnoreValidate(true);
...
}
}
```
## 注册到eureka显示hostname非ip
```properties
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}
```
```xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons</artifactId>
</dependency>
```
参考https://www.jianshu.com/p/5ad8317961b7
## 直接访问服务的swagger-ui.html 提示access forbidden
找到微服务的`OpenServiceConfig.java`重写内部类Swagger2中的swaggerAccessProtected()方法返回false。线上请设置成true
```java
// 开启文档
@Configuration
@EnableSwagger2
public static class Swagger2 extends SwaggerSupport {
@Override
protected String getDocTitle() {
return "故事API";
}
@Override
protected boolean swaggerAccessProtected() {
return false;
}
}
```
## 调试网关出现服务不可用
打断点调试网关出现Read Timeout
参考https://blog.csdn.net/qq_36872046/article/details/81058045
yml添加
```properties
# https://blog.csdn.net/qq_36872046/article/details/81058045
# 路由转发超时时间毫秒默认值1000详见RibbonClientConfiguration.DEFAULT_READ_TIMEOUT。
# 如果微服务端 处理时间过长会导致ribbon read超时解决办法将这个值调大一点
ribbon.ReadTimeout: 60000
```