-
启动springboot项目时候,发现一直无法从config-server获取到对应的配置文件,
报错 Fetching config from server at : http://localhost:8888
-
项目结构如下:
congffig-server的配置如下:
server:
port: 8080
spring:
application:
name: zengyou-config-server
cloud:
config:
server:
git:
uri: https://github.com/你存放config配置文件项目/zengyou-config.git
search-paths: config,config/**
username: 你的git账户
password: git账户密码
label: master
management:
endpoints:
web:
exposure:
include: refresh
eureka:
instance:
preferIpAddress: true
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client:
serviceUrl:
#zengyou-eureka域名已经在host文件配置为127.0.0.1
defaultZone: http://zengyou-eureka:8761/eureka/
- 子项目zengyou-auth的配置如下
server:
port: 8082
spring:
application:
name: zengyou-auth
cloud:
config:
discovery:
enabled: true
service-id: zengyou-config-server
name: zengyou-auth
eureka:
instance:
preferIpAddress: true
instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
client:
serviceUrl:
defaultZone: http://zengyou-eureka:8761/eureka/
查阅资料发现
1.springcloud服务默认去8888端获取配置文件,而我的8888端口分配给了gateway,congfigserver使用的端
口是8080,要想auth项目记载配置好的cong-server的地址,项目的配置文件必须是bootstrap.properties
或 bootstrap.yml配置文件,如果没有的话,则会远程从http://localhost:8888获取配置,然后才会加载
到 application.yml文件,自己恰好写错了成application.yml,改成bootstrap.yml后项目正常启动了
2.之前还犯了一个错误是:
spring.cloud.server.git.search-paths 扫描的路径名称,要对应git上文件路径一样-
改正后项目正常启动,从对应的cong-server获取的对应的配置文件