You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SOP/doc/docs/files/90100_常见问题.md

93 lines
2.1 KiB

6 years ago
# 常见问题
5 years ago
## 微服务端如何获取appId等参数
```java
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext();
String appId = openContext.getAppId();
```
## Socket error occurred: `localhost/0:0:0:0:0:0:0:1:2181`: Connection refused
6 years ago
检查本地zookeeper有没启动,如果zookeeper在其他机器上,修改application-dev.yml
```yaml
cloud:
zookeeper:
connect-string: ip:2181
```
6 years ago
## 如何关闭签名验证
- 针对某一个接口关闭签名验证
`@ApiMapping(value = "alipay.story.get", ignoreValidate = true)`
- 针对所有接口关闭签名验证
```java
@Configuration
public class ZuulConfig extends AlipayZuulConfiguration {
static {
...
ApiConfig.getInstance().setIgnoreValidate(true);
...
}
}
```
## 注册到eureka显示hostname,非ip
```yaml
eureka:
instance:
prefer-ip-address: true
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
5 years ago
## 直接访问服务的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添加:
```yaml
ribbon:
# https://blog.csdn.net/qq_36872046/article/details/81058045
# 路由转发超时时间,毫秒,默认值1000,详见:RibbonClientConfiguration.DEFAULT_READ_TIMEOUT。
# 如果微服务端 处理时间过长,会导致ribbon read超时,解决办法将这个值调大一点
ReadTimeout: 60000
5 years ago
```