SpringCloud——config远程连接github 踩坑

说明

我们现在使用spring cloud config 远程连接github会存在网络跟不上问题,以及本地git密钥问题。

1.github更改了密钥策略原来生成的rsa会导致报错,需要使用命令重新生成ed25519密钥

2.配置需要按照上述配置
force-pull: true #这个参数不加可能会有网络导致连接不上

案例

将工程注册到eureka,需要自助构建项目。

1.新建工程cloud-config-center-3344

2.pom文件

<dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

3.yml(github)

server:
  port: 3344

spring:
  application:
    name:  cloud-config-center #注册进Eureka服务器的微服务名
  cloud:
    config:
      server:
        git:
          uri: https://github.com/****/springcloud2023.git #GitHub上面的git仓库名字
#          username: account #私有仓库才需要账号密码
#          password: password
          search-paths: ####搜索目录
            - springcloud-config
          force-pull: true #
#          ignore-local-ssh-settings: true
          skip-ssl-validation: true
      ####读取分支
      label: main
#服务注册到eureka地址
eureka:
  client:
    service-url:
      defaultZone: http://localhost:7001/eureka

3.yml(gitee)

server:
  port: 3344

spring:
  application:
    name:  cloud-config-center #注册进Eureka服务器的微服务名
  cloud:
    config:
      server:
        git:
          uri: git@gitee.com:/***.git #GitHub上面的git仓库名字
          username: 你的账号 #(开源不需要)私有仓库才需要账号密码
          password: 密码
          search-paths: ####搜索目录
            - 20.springcloud-config
          force-pull: true #
          ignore-local-ssh-settings: true
          skip-ssl-validation: true
          private-key: |
            -----BEGIN RSA PRIVATE KEY-----
            你的.ssh目录下id_rsa内容=
            -----END RSA PRIVATE KEY-----
          default-label: dev
      ####读取分支
      label: dev
#服务注册到eureka地址
eureka:
  client:
    service-url:
      defaultZone: http://localhost:7001/eureka

4.测试

本地浏览器访问:http://localhost:3344/main/config-dev.yml
在这里插入图片描述

  • 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、付费专栏及课程。

余额充值