事件:
公司Spring Cloud项目原先用的注册中心是Eureka,现在准备换成Nacos,Nacos自身带Config Server,所以打算把Spring Cloud Config 也替换掉。
结果启动时警告信息如下:
2019-08-05 17:46:53.018 INFO 32425 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='NACOS', propertySources=[NacosPropertySource {name='user-base-service-dev.yml'}, NacosPropertySource {name='user-base-service.yml'}]}
2019-08-05 17:46:53.027 INFO 32425 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2019-08-05 17:46:53.086 INFO 32425 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available
2019-08-05 17:46:53.086 WARN 32425 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/user-base-service/dev": 拒绝连接 (Connection refused); nested exception is java.net.ConnectException: 拒绝连接 (Connection refused)
2019-08-05 17:46:53.089 INFO 32425 --- [ main] c.d.c.s.u.b.UserBaseServiceApplication : The following profiles are active: dev
原因:
看到输出警告的类为:ConfigServicePropertySourceLocator,盲猜可能是Spring Cloud微服务项目在注解了@SpringCloudApplication以后,认为你用的是Spring Cloud Config自动去加载Spring Cloud Config默认的配置信息。但是你并没有配置spring.cloud.config.url属性,所有采用了默认地址:http://localhost:8888
解决:
更改 bootstrap.yml配置文件,添加 spring.cloud.config = false 。
原配置文件为:
spring:
application:
name: user-base-service
profiles:
active: dev
cloud:
nacos:
config:
server-addr: 192.168.1.35:8848
file-extension: yml
更改后为:
spring:
application:
name: user-base-service
profiles:
active: dev
cloud:
config:
enabled: false
nacos:
config:
server-addr: 192.168.1.35:8848
file-extension: yml
重新启动微服务,结果成功了。没有了ConfigServicePropertySourceLocator的警告信息。