I’m using Spring Cloud API Gateway (MVC) – org.springframework.cloud:spring-cloud-starter-gateway-mvc
and I have a route setup in application.yaml that I would like to move to a bean configuration.
In application.yaml
, an example route setup is as follows:
spring:
cloud:
gateway:
mvc:
http-client:
type: autodetect
routes:
- id: mock-route-id
uri: ${mock-service-uri: http://mock-service:8080}
predicates:
- Method=GET
- Path=/v1/resource-name/method-name
- Query=queryParam
filters:
- SetPath=/downstreamResource/{queryParam}
What should the route like in the Spring Cloud API Gateway (MVC) bean format? I’m specifically interested it knowing how to setup the URI property key so that I can test it with WireMock.
As I understand, the bean would be in Application.java, below the main method.
To illustrate what I am looking for:
@Bean
public RouterFunction<ServerResponse> myRoutes() {
return route("routeName")
.route(RequestPredicates.path("/v1/resource-name/method-name", "http://mock-service:8080"))
.build();
}
I am asking for this because I am trying to test the route with WireMock and Wiremock requires the bean to be injected into the Test class using the following annotation:
@EnableWireMock({@ConfigureWireMock(name="mock-service", property = "mock-service-uri"
Related WireMock docs: https://wiremock.org/docs/solutions/spring-boot
I’ve tried to configure it myself as a bean, but can’t find documentation that clearly explains how to do this.