使用Spring Cloud Gateway的简单网关 - ProxyExchange

时间:2018-04-30 15:48:31

标签: spring-cloud spring-cloud-gateway

我想用Spring云编写一个简单的网关,这样对第三方的请求似乎来自我的服务(就像我过去和Zuul一样)。

github page上的示例以及official docs中的示例似乎正是我想要的。即一个简单的控制器路由,用于代理对给定路由的所有请求:

@GetMapping("/proxy/path/**")
public ResponseEntity<?> proxyPath(ProxyExchange<?> proxy) throws Exception {
  String path = proxy.path("/proxy/path/");
  return proxy.uri(home.toString() + "/foos/" + path).get();
}

但我遇到的问题是,人工制品spring-cloud-starter-gateway不包括org.springframework.cloud.gateway.mvc.ProxyExchange

要获取ProxyExchange,我需要添加与spring-cloud-gateway-mvc不兼容的人工制品spring-cloud-starter-gateway。将这两件事包括在一起会导致以下错误:

***************************************************
Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway 
at this time. Please remove spring-boot-starter-web dependency.
***************************************************

因此,我不得不使用以下两个依赖项来使基本网关工作:

  • spring-cloud-gateway
  • spring-cloud-gateway-mvc

哪个,工作正常,直到我需要在项目的其他地方使用org.springframework.cloud.gateway.filter.*包,这意味着我需要包括:

  • spring-cloud-gateway-core,或
  • spring-cloud-starter-gateway

这意味着我回到了 incompatability banner

有没有使用简单的API网关功能只有spring-cloud-starter-gateway依赖项,因为文档暗示应该可行?我使用的版本 2.0.0.RC1

compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-gateway', version: '2.0.0.RC1'

0 个答案:

没有答案
相关问题