|
|
|
@ -44,7 +44,7 @@ return method.replace('.', '_') + "_response"; |
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
@Configuration |
|
|
|
|
public class ZuulConfig extends AlipayZuulConfiguration { |
|
|
|
|
public class MyConfig { |
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
... |
|
|
|
@ -84,23 +84,18 @@ public class ZuulConfig extends AlipayZuulConfiguration { |
|
|
|
|
|
|
|
|
|
如果想要对微服务结果做更深一步处理,步骤如下: |
|
|
|
|
|
|
|
|
|
1. 新增一个类,继承`ZuulResultExecutor.java`,并重写`public String merge(T exchange, JSONObject responseData)`方法 |
|
|
|
|
|
|
|
|
|
方法merge参数说明如下: |
|
|
|
|
|
|
|
|
|
exchange:RequestContext对象 |
|
|
|
|
responseData:微服务端返回的结果 |
|
|
|
|
|
|
|
|
|
方法返回最终结果 |
|
|
|
|
1. 新增一个类,继承`GatewayResultExecutor.java`,并重写`String mergeResult(T request, String serviceResult)`方法 |
|
|
|
|
|
|
|
|
|
2. 配置自定义类 |
|
|
|
|
|
|
|
|
|
```java |
|
|
|
|
public class SopGatewayApplication { |
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
ApiConfig.getInstance().setZuulResultExecutor(new MyzuulResultExecutor()); |
|
|
|
|
SpringApplication.run(SopGatewayApplication.class, args); |
|
|
|
|
@Configuration |
|
|
|
|
public class MyConfig { |
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
... |
|
|
|
|
ApiConfig.getInstance().setGatewayResultExecutor(new MyGatewayResultExecutor()); |
|
|
|
|
... |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|