5

我想使用 spring cloud 编写一个简单的网关,以便对第三方的请求看起来来自我的服务(就像我过去使用 Zuul 所做的那样)。

github页面上的示例以及官方文档中的示例似乎正是我想要的。即一个简单的控制器路由,将所有请求代理到给定路由:

@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

这意味着我又回到了不兼容横幅


spring-cloud-starter-gateway正如文档所暗示的那样,是否可以仅使用依赖项来使用简单的 API 网关功能?我正在使用的版本2.0.0.RC1

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

0 回答 0