我正在尝试将 GatewayApplication 连接到 Eureka 服务器。 以下是 Eureka 客户端的 application.yml。我正在开发配置文件上运行它并已验证相同。
spring:
application:
name: GatewayApplication
---
spring:
config:
activate:
on-profile: Development
server:
port: 8080
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/
instance:
preferIpAddress: true
hostname: localhost
---
spring:
config:
activate:
on-profile: Production
server:
port: 8080
eureka:
client:
serviceUrl:
defaultZone: ${EUREKA_HOST:http://localhost:8761/eureka/}
instance:
preferIpAddress: true
hostname: localhost
这是客户端应用程序控制台上的输出:
2024-12-21T13:31:57.367+05:30 WARN 4302 --- [GatewayApplication] [ main] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: Unable to set redirect follow using reflection
2024-12-21T13:31:57.374+05:30 INFO 4302 --- [GatewayApplication] [ main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GATEWAYAPPLICATION/fedora:GatewayApplication:8080 - was unable to refresh its cache! This periodic background refresh will be retried in 30 seconds. status = Cannot execute request on any known server stacktrace = com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137)
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:76)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134)
at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1046)
at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:961)
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:410)
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:245)
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:240)
at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:68)
at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:324)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:171)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiateWithFactoryMethod(SimpleInstantiationStrategy.java:88)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:168)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:645)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1351)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1181)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:563)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:523)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:375)
at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:375)
at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:179)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:372)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getTargetObject(EurekaRegistration.java:128)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient(EurekaRegistration.java:116)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:281)
at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:482)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:727)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration$$SpringCGLIB$$0.getEurekaClient(<generated>)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:83)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:66)
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:89)
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:323)
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:510)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:295)
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:240)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:1006)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:630)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
at com.PokerAI.GatewayApplication.GatewayApplication.main(GatewayApplication.java:11)
2024-12-21T13:31:57.374+05:30 INFO 4302 --- [GatewayApplication] [ main] com.netflix.discovery.DiscoveryClient : Initial registry fetch from primary servers failed
2024-12-21T13:31:57.374+05:30 WARN 4302 --- [GatewayApplication] [ main] com.netflix.discovery.DiscoveryClient : Using default backup registry implementation which does not do anything.
2024-12-21T13:31:57.375+05:30 INFO 4302 --- [GatewayApplication] [ main] com.netflix.discovery.DiscoveryClient : Initial registry fetch from backup servers failed
2024-12-21T13:31:57.376+05:30 INFO 4302 --- [GatewayApplication] [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2024-12-21T13:31:57.380+05:30 INFO 4302 --- [GatewayApplication] [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2024-12-21T13:31:57.385+05:30 INFO 4302 --- [GatewayApplication] [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1734768117382 with initial instances count: 0
2024-12-21T13:31:57.393+05:30 INFO 4302 --- [GatewayApplication] [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application GATEWAYAPPLICATION with eureka with status UP
2024-12-21T13:31:57.395+05:30 INFO 4302 --- [GatewayApplication] [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1734768117395, current=UP, previous=STARTING]
2024-12-21T13:31:57.398+05:30 INFO 4302 --- [GatewayApplication] [foReplicator-%d] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GATEWAYAPPLICATION/fedora:GatewayApplication:8080: registering service...
2024-12-21T13:31:57.404+05:30 WARN 4302 --- [GatewayApplication] [foReplicator-%d] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: Unable to set redirect follow using reflection
2024-12-21T13:31:57.405+05:30 WARN 4302 --- [GatewayApplication] [foReplicator-%d] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GATEWAYAPPLICATION/fedora:GatewayApplication:8080 - registration failed Cannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:76) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:828) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:125) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.InstanceInfoReplicator$2.run(InstanceInfoReplicator.java:105) ~[eureka-client-2.0.4.jar:2.0.4]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
2024-12-21T13:31:57.415+05:30 WARN 4302 --- [GatewayApplication] [foReplicator-%d] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:76) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:828) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:125) ~[eureka-client-2.0.4.jar:2.0.4]
at com.netflix.discovery.InstanceInfoReplicator$2.run(InstanceInfoReplicator.java:105) ~[eureka-client-2.0.4.jar:2.0.4]
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572) ~[na:na]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) ~[na:na]
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[na:na]
2024-12-21T13:31:57.435+05:30 INFO 4302 --- [GatewayApplication] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
2024-12-21T13:31:57.439+05:30 INFO 4302 --- [GatewayApplication] [ main] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 8080
2024-12-21T13:31:57.482+05:30 INFO 4302 --- [GatewayApplication] [ main] c.P.G.GatewayApplication : Started GatewayApplication in 6.574 seconds (process running for 8.116)
2024-12-21T13:32:12.491+05:30 INFO 4302 --- [GatewayApplication] [ionShutdownHook] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application GATEWAYAPPLICATION with eureka with status DOWN
2024-12-21T13:32:12.492+05:30 INFO 4302 --- [GatewayApplication] [ionShutdownHook] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1734768132492, current=DOWN, previous=UP]
2024-12-21T13:32:12.493+05:30 INFO 4302 --- [GatewayApplication] [foReplicator-%d] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GATEWAYAPPLICATION/fedora:GatewayApplication:8080: registering service...
2024-12-21T13:32:12.498+05:30 WARN 4302 --- [GatewayApplication] [foReplicator-%d] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: Unable to set redirect follow using reflection
2024-12-21T13:32:12.498+05:30 INFO 4302 --- [GatewayApplication] [ionShutdownHook] o.s.b.w.e.tomcat.GracefulShutdown : Commencing graceful shutdown. Waiting for active requests to complete
2024-12-21T13:32:12.499+05:30 WARN 4302 --- [GatewayApplication] [foReplicator-%d] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GATEWAYAPPLICATION/fedora:GatewayApplication:8080 - registration failed Cannot execute request on any known server
这是服务器应用程序的 application.yml
spring:
application:
name: DiscoveryService
---
spring:
config:
activate:
on-profile: Development
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
---
# TODO: Change as needed in Production
spring:
config:
activate:
on-profile: Production
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
这在开发配置文件中也处于活动状态
尝试使用 eureka 父级的不同属性更改 YAML 文件,但未对行为进行任何更改。
想出了解决办法。我使用的是 spring-cloud-starter-gateway-mvc 依赖项而不是 spring-cloud-starter-gateway。