SpringCloud微服务搭建入坑指南

目录

使用Github配置中心文件时。若文件为.properties则生效,若采用.yml则不生效

明明Github已经连接成功,但一直报错,且拿不到配置文件

启动配置中心项目,且Github已经连接成功,进行读取配置文件测试时,页面404

使用spring gateway配置网关时,报错 was unable to send heartbeat!



使用Github配置中心文件时。若文件为.properties则生效,若采用.yml则不生效

原因:yml格式的配置方式,“:”后必须要有空格,才会被识别

解决

server:

     port: 8080  #正确

     port:8080  #错误

明明Github已经连接成功,但一直报错,且拿不到配置文件

原因:一般情况下是你的配置文件没有放在仓库根目录下,它找不到

解决:在配置项目(我的是config-server)的配置文件(application.properties)中配置文件路径

//application.properties

#git 配置中心仓库的地址
spring.cloud.config.server.git.uri=https://github.com/XXX/config-center.git
spring.cloud.config.server.git.username=XXX
spring.cloud.config.server.git.password=XXX

#配置文件路径
spring.cloud.config.server.git.searchPaths=spring-cloud-config  //(我的是spring-cloud-config)

启动配置中心项目,且Github已经连接成功,进行读取配置文件测试时,页面404

原因:github上的配置文件的名字构成必须是: {application}-{profile}.properties 等方式,仓库中的配置文件会被转换成web接口,否则不会转换,自然就是404

查看更多

解决:更改文件命名格式,如 application-dev.properties 即可

使用spring gateway配置网关时,报错 was unable to send heartbeat!

原因:配置注册中心地址错误

解决:

eureka.client.service-url.defaultZone=xxx  //(错误)
eureka.client.service-url.default=xxx  //(正确)

猜你喜欢

转载自blog.csdn.net/qq_28202661/article/details/96994671