在SpringCloud中Server端启动成功了,再去启动Client项目,可能会出现这样的问题,Console日志如下:
2022-06-22 16:04:41.990 INFO 14964 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:9001/
2022-06-22 16:04:42.560 INFO 14964 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=config, profiles=[test], label=master, version=28afd1f94d37c7a7fc60e402dab302bb178fae5c, state=null
2022-06-22 16:04:42.560 INFO 14964 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-https://gitee.com/llongtong/zeno-training-platform-config.git/file:C:\Users\SAMSUNG\AppData\Local\Temp\config-repo-7871456846147239475\config-test.yml'}]
2022-06-22 16:04:42.576 INFO 14964 --- [ main] com.zeno.ConfigClientTestApplication : No active profile set, falling back to default profiles: default
2022-06-22 16:04:42.866 INFO 14964 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=788e2244-e364-3193-959b-c9162cfcdae6
2022-06-22 16:04:43.971 INFO 14964 --- [ main] DiscoveryClientOptionalArgsConfiguration : Eureka HTTP Client uses RestTemplate.
2022-06-22 16:04:44.845 WARN 14964 --- [ 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-06-22 16:04:44.892 INFO 14964 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2022-06-22 16:04:44.923 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2022-06-22 16:04:44.923 INFO 14964 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2022-06-22 16:04:44.939 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2022-06-22 16:04:44.939 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2022-06-22 16:04:44.939 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2022-06-22 16:04:44.939 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2022-06-22 16:04:44.939 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2022-06-22 16:04:44.939 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2022-06-22 16:04:44.939 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2022-06-22 16:04:45.111 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : The response status is 200
2022-06-22 16:04:45.111 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2022-06-22 16:04:45.111 INFO 14964 --- [ main] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2022-06-22 16:04:45.111 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1655885085111 with initial instances count: 3
2022-06-22 16:04:45.111 INFO 14964 --- [ main] o.s.c.n.e.s.EurekaServiceRegistry : Registering application CONFIG-CLIENT with eureka with status UP
2022-06-22 16:04:45.111 INFO 14964 --- [ main] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1655885085111, current=UP, previous=STARTING]
2022-06-22 16:04:45.126 INFO 14964 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-CLIENT/LONGTONG.mshome.net:config-client:8453: registering service...
2022-06-22 16:04:45.126 INFO 14964 --- [ main] com.zeno.ConfigClientTestApplication : Started ConfigClientTestApplication in 5.828 seconds (JVM running for 8.011)
2022-06-22 16:04:45.142 INFO 14964 --- [ionShutdownHook] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application CONFIG-CLIENT with eureka with status DOWN
2022-06-22 16:04:45.142 INFO 14964 --- [ionShutdownHook] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1655885085142, current=DOWN, previous=UP]
2022-06-22 16:04:45.142 INFO 14964 --- [ionShutdownHook] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2022-06-22 16:04:45.173 INFO 14964 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-CLIENT/LONGTONG.mshome.net:config-client:8453 - registration status: 204
2022-06-22 16:04:45.173 INFO 14964 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-CLIENT/LONGTONG.mshome.net:config-client:8453: registering service...
2022-06-22 16:04:45.173 INFO 14964 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-CLIENT/LONGTONG.mshome.net:config-client:8453 - registration status: 204
2022-06-22 16:04:45.173 INFO 14964 --- [ionShutdownHook] com.netflix.discovery.DiscoveryClient : Unregistering ...
2022-06-22 16:04:45.173 INFO 14964 --- [ionShutdownHook] com.netflix.discovery.DiscoveryClient : DiscoveryClient_CONFIG-CLIENT/LONGTONG.mshome.net:config-client:8453 - deregister status: 200
2022-06-22 16:04:45.189 INFO 14964 --- [ionShutdownHook] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
Process finished with exit code 0
其中,出了问题的大概可以从这里排查。
前面显示注册成功了,现在立马又开始倒戈。这是由于可能SpringWeb依赖是继承父模块的,所以我们这个模块里没有写Web依赖。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
在我们这个模块pom文件里加上web依赖就搞定了。