我的 spring api 网关有问题,因为我在请求路线时没有得到结果。 我有 3 项服务,我只需将请求发送到一个 api 网关来处理即将到来的请求 当我尝试访问服务时,我没有收到此消息:
{
"timestamp": "2022-01-07T16:52:50.076+00:00",
"path": "/tva/",
"status": 404,
"error": "Not Found",
"message": null,
"requestId": "8527c006-1"
}
所以我没有得到任何回应 我的服务Application.yml文件:
server:
port: 9003
spring:
application:
name: TVA-SERVICE
eureka:
instance:
hostname: localhost
client:
fetch-registry: true
register-with-eureka: true
service-url:
defaultZone: http://localhost:8761/eureka/
API 网关的 application.yml 文件:
server:
port: 9191
spring:
application:
name: API-GATEWAY
cloud:
gateway:
routes:
- id: ELECTRICITY-SERVICE
uri: lb://ELECTRICITY-SERVICE
predicates:
- Path=/users/**
- Path=/bills/**
- id: TVA-SERVICE
uri: lb://TVA-SERVICE
predicates:
- Path=/tva/**
- id: BA-SERVICE
uri: lb://BA-SERVICE
predicates:
- Path=/ba/**
eureka:
instance:
hostname: localhost
client:
fetch-registry: true
register-with-eureka: true
server-url:
defaultZone: http://localhost:8761/eureka/
这是服务注册的 Application.yml 文件:
server:
port: 8761
eureka:
client:
register-with-eureka: false
fetch-registry: false
这是我运行 api 网关时收到的消息
2022-01-07 17:52:33.664 INFO 16600 --- [ main] c.t.c.CloudGatewayApplication : Starting CloudGatewayApplication using Java 17 on LAPTOP-NQ9LQJBB with PID 16600 (C:\Users\PREDATOR\Desktop\workspace\jee project backend\cloud-gateway\target\classes started by PREDATOR in C:\Users\PREDATOR\Desktop\workspace\jee project backend\cloud-gateway)
2022-01-07 17:52:33.665 INFO 16600 --- [ main] c.t.c.CloudGatewayApplication : No active profile set, falling back to default profiles: default
2022-01-07 17:52:34.305 INFO 16600 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=e884b174-a379-383b-bee7-679825ad255c
2022-01-07 17:52:34.347 INFO 16600 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-01-07 17:52:34.348 INFO 16600 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration$ReactorDeferringLoadBalancerFilterConfig' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration$ReactorDeferringLoadBalancerFilterConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-01-07 17:52:34.348 INFO 16600 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'reactorDeferringLoadBalancerExchangeFilterFunction' of type [org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2022-01-07 17:52:35.713 INFO 16600 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [After]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Before]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Between]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Cookie]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Header]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Host]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Method]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Path]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Query]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [ReadBody]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [RemoteAddr]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Weight]
2022-01-07 17:52:35.964 INFO 16600 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [CloudFoundryRouteService]
2022-01-07 17:52:37.254 INFO 16600 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2022-01-07 17:52:38.457 INFO 16600 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2022-01-07 17:52:38.516 INFO 16600 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator'
2022-01-07 17:52:38.632 INFO 16600 --- [ main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses RestTemplate.
2022-01-07 17:52:38.666 WARN 16600 --- [ main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath.
2022-01-07 17:52:38.704 INFO 16600 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2022-01-07 17:52:38.734 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2022-01-07 17:52:38.737 INFO 16600 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2022-01-07 17:52:38.755 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2022-01-07 17:52:38.755 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2022-01-07 17:52:38.755 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2022-01-07 17:52:38.755 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2022-01-07 17:52:38.755 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2022-01-07 17:52:38.755 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2022-01-07 17:52:38.755 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2022-01-07 17:52:38.965 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
2022-01-07 17:52:38.969 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2022-01-07 17:52:38.973 INFO 16600 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2022-01-07 17:52:38.982 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1641574358981 with initial instances count: 3
2022-01-07 17:52:38.982 INFO 16600 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application API-GATEWAY with eureka with status UP
2022-01-07 17:52:38.983 INFO 16600 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1641574358983, current=UP, previous=STARTING]
2022-01-07 17:52:38.984 INFO 16600 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_API-GATEWAY/localhost:API-GATEWAY:9191: registering service...
2022-01-07 17:52:39.010 INFO 16600 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_API-GATEWAY/localhost:API-GATEWAY:9191 - registration status: 204
2022-01-07 17:52:39.148 INFO 16600 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port 9191
2022-01-07 17:52:39.149 INFO 16600 --- [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 9191
2022-01-07 17:52:40.351 INFO 16600 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2022-01-07 17:52:41.541 INFO 16600 --- [ main] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2022-01-07 17:52:41.557 INFO 16600 --- [ main] c.t.c.CloudGatewayApplication : Started CloudGatewayApplication in 9.384 seconds (JVM running for 9.926)
2022-01-07 17:57:38.758 INFO 16600 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
我也遇到了同样的问题,结果发现是添加了错误的依赖项。使用“spring-cloud-starter-gateway”代替“spring-cloud-starter-gateway-mvc”。所有其他事情保持不变。 结果第一个依赖项仅与某些版本的 java 和 spring cloud 兼容。