【踩坑专栏】spring cloud的config组件拉去不到github配置文件的坑

注意,即使是public的repo,也需要在配置文件里注明用户名和密码,或者私钥才行,不然结果就是404,后台看日志就是超时!

部分config的配置如下:

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/xxxx/config-repo.git
          #强制拉去资源文件
          force-pull: true
          #默认分支
          default-label: main
          username: xxxx
          password: xxxx

请求路径:
http://localhost:port/label/文件名字.yml
经测试,只有这种格式可以拉去到配置,格式可以不同,如.yml或.json等,会自动做转换

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot Cloud 远程配置可以使用 GitHub 存储配置文件,以便在不同的环境中使用相同的配置。以下是如何在 Spring Boot Cloud 中使用 GitHub 存储配置文件的步骤: 1. 在 GitHub 上创建一个仓库,并在仓库中创建一个名为 `application.yml` 的配置文件,内容如下: ``` server: port: 8080 spring: datasource: url: jdbc:mysql://localhost:3306/mydb username: myuser password: mypassword ``` 2. 在 Spring Boot 项目的 `src/main/resources` 目录中创建一个名为 `bootstrap.yml` 的配置文件,内容如下: ``` spring: cloud: config: uri: https://github.com/your-github-username/your-github-repo/ username: your-github-username password: your-github-password profile: dev ``` 其中,`uri` 指定了 GitHub 仓库的 URL,`username` 和 `password` 是 GitHub 的用户名和密码,`profile` 指定了要使用的配置文件的环境。 3. 在 Spring Boot 项目中添加以下 Maven 依赖: ``` <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> ``` 4. 在 Spring Boot 项目的启动类上添加 `@EnableConfigServer` 注解: ``` @EnableConfigServer @SpringBootApplication public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } } ``` 5. 启动 Spring Boot 项目,访问 `http://localhost:8080/application/dev` 可以看到 GitHub 上的配置文件已被加载。 以上就是使用 GitHub 存储配置文件的 Spring Boot Cloud 远程配置的步骤。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值