Spring Cloud Gateway gives 404 route error

Viewed 33

Spring cloud gateway does not forward my request to the next microservice. The result is always 404.

@SpringBootApplication
public class TwoFactorAuthenticationServiceApplication {

 @Bean
 public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
 return builder.routes()
 .route("path_route", r -> r.path("/two-factor-authentication-service-1.0/get")
 .uri("http://localhost:10270/wallet-management-service-1.0/api/system-wallet/get-wallet-address"))
 .route("host_route", r -> r.host("*.myhost.org")
 .uri("http://httpbin.org"))
 .build();
 }

 public static void main(String[] args) {
 SpringApplication.run(TwoFactorAuthenticationServiceApplication.class, args);
 }

}

The response is

2022-09-21 15:13:35.349 TRACE 20640 --- [ XNIO-1 I/O-2] o.s.c.g.h.p.PathRoutePredicateFactory : Pattern "/two-factor-authentication-service-1.0/get" matches against value "/two-factor-authentication-service-1.0/get"
2022-09-21 15:13:35.350 DEBUG 20640 --- [ XNIO-1 I/O-2] o.s.c.g.h.RoutePredicateHandlerMapping : Route matched: path_route
2022-09-21 15:13:35.350 DEBUG 20640 --- [ XNIO-1 I/O-2] o.s.c.g.h.RoutePredicateHandlerMapping : Mapping [Exchange: GET http://localhost:10340/two-factor-authentication-service-1.0/get?userId=1951] to Route{id='path_route', uri=http://localhost:10270/wallet-management-service-1.0/api/system-wallet/get-wallet-address, order=0, predicate=Paths: [/two-factor-authentication-service-1.0/get], match trailing slash: true, gatewayFilters=[], metadata={}}
2022-09-21 15:13:35.351 DEBUG 20640 --- [ XNIO-1 I/O-2] o.s.c.g.h.RoutePredicateHandlerMapping : [4406f4fd-1] Mapped to org.springframework.cloud.gateway.handler.FilteringWebHandler@5f0b2fe1
2022-09-21 15:13:35.351 DEBUG 20640 --- [ XNIO-1 I/O-2] o.s.c.g.handler.FilteringWebHandler : Sorted gatewayFilterFactories: [[GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RemoveCachedBodyFilter@6dacde96}, order = -2147483648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.AdaptCachedBodyGlobalFilter@32180efb}, order = -2147482648], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyWriteResponseFilter@39240aa3}, order = -1], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardPathFilter@16a3d9a7}, order = 0], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.GatewayMetricsFilter@5e537465}, order = 0], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter@47a05ad8}, order = 10000], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.config.GatewayNoLoadBalancerClientAutoConfiguration$NoLoadBalancerClientFilter@33c5cc0}, order = 10150], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.WebsocketRoutingFilter@1caa1866}, order = 2147483646], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.NettyRoutingFilter@685e97e0}, order = 2147483647], [GatewayFilterAdapter{delegate=org.springframework.cloud.gateway.filter.ForwardRoutingFilter@283240b0}, order = 2147483647]]
2022-09-21 15:13:35.358 TRACE 20640 --- [ XNIO-1 I/O-2] o.s.c.g.filter.RouteToRequestUrlFilter : RouteToRequestUrlFilter start
2022-09-21 15:13:35.515 TRACE 20640 --- [ctor-http-nio-2] o.s.c.gateway.filter.NettyRoutingFilter : outbound route: 5ff7309e, inbound: [4406f4fd-1]
2022-09-21 15:13:35.580 TRACE 20640 --- [ctor-http-nio-2] o.s.c.g.filter.NettyWriteResponseFilter : NettyWriteResponseFilter start inbound: 5ff7309e, outbound: [4406f4fd-1]
2022-09-21 15:13:35.612 TRACE 20640 --- [ctor-http-nio-2] o.s.c.g.filter.GatewayMetricsFilter : spring.cloud.gateway.requests tags: [tag(httpMethod=GET),tag(httpStatusCode=404),tag(outcome=CLIENT_ERROR),tag(routeId=path_route),tag(routeUri=http://localhost:10270/wallet-management-service-1.0/api/system-wallet/get-wallet-address),tag(status=NOT_FOUND)]```
1 Answers

The problem seemed My application works on spring MVC and Spring cloud gateway is for webflux only.

Related