Simple Gateway Using Spring Cloud Gateway - ProxyExchange

匿名 (未验证) 提交于 2019-12-03 01:18:02

问题:

I wanted to write a simple gateway using spring cloud, so that requests to a third party would appear to come from my service (as I have done so in the past with Zuul).

The example on the github page and likewise in the official docs seems to be exactly what I want. i.e. a simple controller route to proxy all requests to a given route:

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

But the problem I have, is that the artefact spring-cloud-starter-gateway does not include org.springframework.cloud.gateway.mvc.ProxyExchange.

To get the ProxyExchange, I need to include the artefact spring-cloud-gateway-mvc, which is not compatible with spring-cloud-starter-gateway. Including these two things together causes the following error:

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

So, I'm forced to use the following two dependencies to get a basic Gateway to work:

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

Which, works fine, untill I need to use the org.springframework.cloud.gateway.filter.* packages somewhere else in the project, which means that I need to include:

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

Which means that I'm back to the incompatability banner.


Is there anyway to use the simple API gateway features with just the spring-cloud-starter-gateway dependency, as the documentation implies should be possible? The version I'm using 2.0.0.RC1.

compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-gateway', version: '2.0.0.RC1' 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!