问题
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
, ORspring-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'
来源:https://stackoverflow.com/questions/50103964/simple-gateway-using-spring-cloud-gateway-proxyexchange