|
|
@ -1,10 +1,5 @@ |
|
|
|
# 常见问题 |
|
|
|
# 常见问题 |
|
|
|
|
|
|
|
|
|
|
|
## 在zuul过滤器中获取请求参数 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
ApiParam param = ZuulContext.getApiParam(); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 在SpringCloudGateway中获取请求参数 |
|
|
|
## 在SpringCloudGateway中获取请求参数 |
|
|
|
|
|
|
|
|
|
|
@ -15,41 +10,15 @@ ApiParam apiParam = ServerWebExchangeUtil.getApiParam(exchange); |
|
|
|
## 微服务端如何获取appId等参数 |
|
|
|
## 微服务端如何获取appId等参数 |
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
```java |
|
|
|
OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext(); |
|
|
|
String app_id = request.getParameter("app_id"); |
|
|
|
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); |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 如何关闭签名验证 |
|
|
|
## 如何关闭签名验证 |
|
|
|
|
|
|
|
|
|
|
|
- 针对某一个接口关闭签名验证 |
|
|
|
- 针对某一个接口关闭签名验证 |
|
|
|
`@Open(value = "alipay.story.get", ignoreValidate = true)` |
|
|
|
`@Open(value = "alipay.story.get", ignoreValidate = true)` |
|
|
|
|
|
|
|
|
|
|
|
- 针对所有接口关闭签名验证 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
|
|
|
@Configuration |
|
|
|
|
|
|
|
public class ZuulConfig extends AlipayZuulConfiguration { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
|
|
|
... |
|
|
|
|
|
|
|
ApiConfig.getInstance().setIgnoreValidate(true); |
|
|
|
|
|
|
|
... |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 注册到eureka显示hostname,非ip |
|
|
|
## 注册到eureka显示hostname,非ip |
|
|
|
|
|
|
|
|
|
|
@ -103,26 +72,6 @@ yml添加: |
|
|
|
ribbon.ReadTimeout= 60000 |
|
|
|
ribbon.ReadTimeout= 60000 |
|
|
|
``` |
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
## 指定了context-path(拉取路由404) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
微服务项目定义了`server.servlet.context-path=/story-service`,同时必须指定: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```properties |
|
|
|
|
|
|
|
spring.cloud.nacos.discovery.metadata.context-path=${server.servlet.context-path} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
yml配置如下: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```yaml |
|
|
|
|
|
|
|
spring: |
|
|
|
|
|
|
|
cloud: |
|
|
|
|
|
|
|
nacos: |
|
|
|
|
|
|
|
discovery: |
|
|
|
|
|
|
|
metadata: |
|
|
|
|
|
|
|
context-path: ${server.servlet.context-path} |
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
不然网关无法拉取路由信息 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 其它微服务没有开放接口,需要排除 |
|
|
|
## 其它微服务没有开放接口,需要排除 |
|
|
|
|
|
|
|
|
|
|
|