我正在尝试Spring-cloud-gateway。在浏览documentation时,我发现我们不仅可以在yml/ properties文件中配置路由,还可以使用Fluent routes API配置路由。以下是文档中的代码片段。
@Bean
public RouteLocator customRouteLocator(ThrottleGatewayFilterFactory throttle) {
return Routes.locator()
.route("test")
.predicate(host("**.abc.org").and(path("/image/png")))
.addResponseHeader("X-TestHeader", "foobar")
.uri("http://httpbin.org:80")
.route("test2")
.predicate(path("/image/webp"))
.add(addResponseHeader("X-AnotherHeader", "baz"))
.uri("http://httpbin.org:80")
.route("test3")
.order(-1)
.predicate(host("**.throttle.org").and(path("/get")))
.add(throttle.apply(tuple().of("capacity", 1,
"refillTokens", 1,
"refillPeriod", 10,
"refillUnit", "SECONDS")))
.uri("http://httpbin.org:80")
.build();
}但是我找不到这个类Routes。不知道我是不是错过了什么。我使用的是spring boot 2.0.0.M7,其中包含了spring-cloud-starter-gateway depependecy。
有什么想法吗?
发布于 2018-03-02 02:16:33
Routes不再可用。向customRouteLocator添加一个RouteLocatorBuilder参数。我会修好文档的。
https://stackoverflow.com/questions/49051560
复制相似问题