Closed Layfolk-zcy closed 2 years ago
you have to config it to a route.
@Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route(p -> p
.path("/get")
.filters(f -> f.addRequestHeader("Hello", "World"))
.uri("http://httpbin.org:80"))
.route(p -> p
.path("/test")
.filters(f -> f.filter(new YourGatewayFilter()))
.uri("http://httpbin.org:80")).
build();
}
you have to config it to a route.
@Bean public RouteLocator myRoutes(RouteLocatorBuilder builder) { return builder.routes() .route(p -> p .path("/get") .filters(f -> f.addRequestHeader("Hello", "World")) .uri("http://httpbin.org:80")) .route(p -> p .path("/test") .filters(f -> f.filter(new YourGatewayFilter())) .uri("http://httpbin.org:80")). build(); }
but the route information is definited in yml.application. why i need to definit above the code.
i am faced with the same issue. has this issue been solved?
i am faced with the same issue. has this issue been solved?
# config bootstrap.yml or application.yml
spring:
cloud:
gateway:
discovery:
locator:
enabled: false
routes:
- id: xxx
you have to config it to a route.
@Bean public RouteLocator myRoutes(RouteLocatorBuilder builder) { return builder.routes() .route(p -> p .path("/get") .filters(f -> f.addRequestHeader("Hello", "World")) .uri("http://httpbin.org:80")) .route(p -> p .path("/test") .filters(f -> f.filter(new YourGatewayFilter())) .uri("http://httpbin.org:80")). build(); }
but the route information is definited in yml.application. why i need to definit above the code.
config file yml is ok, but you need do config like below:
# config bootstrap.yml or application.yml
spring:
cloud:
gateway:
discovery:
locator:
enabled: false
routes:
- id: xxx
@Component public class AuthGlobalFilter implements Ordered, GlobalFilter {
}
@RestController public class TestController {
}