1.微服务报错原文:
2020-01-05 13:14:03.080 INFO 195216 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-01-05 13:14:04.227 INFO 195216 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2020-01-05 13:14:04.228 WARN 195216 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/service-hi/default": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
2020-01-05 13:14:04.230 INFO 195216 --- [ main] c.e.e.EurekaClientApplication : No active profile set, falling back to default profiles: default
2020-01-05 13:14:04.547 INFO 195216 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=2e19fb5c-dae4-32ce-beec-3c04e2b7fe27
2020-01-05 13:14:06.164 INFO 195216 --- [ main] c.e.e.EurekaClientApplication : Started EurekaClientApplication in 5.6 seconds (JVM running for 7.7)
2.其中pom文件配置
server:
port: 8762
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: service-A
从 上面报错看出显示这个项目连接的server为默认的8888端口,并不是我项目配置文件中设定的8762端口;
通过错误日志,发现服务还是取的8888的配置中心的文件,这就涉及到了一个配置文件的优先级,在spring Cloud 中,有个 "启动上下文",用来加载ConfigServer里面的配置,默认的加载顺序为:bootstrap.*配置 --> 链接 configServer,加载远程配置 --> 加载application.* 配置。
3.解决方案
在pom.xml文件加入下面这个依赖,完美的解决问题
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>