简体   繁体   English

Spring 云网关出现404路由错误

[英]Spring Cloud Gateway gives 404 route error

Spring cloud gateway does not forward my request to the next microservice. Spring 云网关没有将我的请求转发到下一个微服务。 The result is always 404.结果始终为 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)]```

The problem seemed My application works on spring MVC and Spring cloud gateway is for webflux only.问题似乎我的应用程序适用于 spring MVC 和 Spring 云网关仅适用于 webflux。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM