Spring Cloud Config 配置 git 时遇到的坑

本文记录了在配置SpringCloudConfig时遇到的GitSSH错误,通过在pom.xml添加依赖、配置application.yml并设置ignore-local-ssh-settings和private-key解决了问题。关键步骤包括:添加SpringCloudConfig和Eureka依赖,配置Git仓库地址和SSH私钥,并强调了SSH配置的注意事项。
摘要由CSDN通过智能技术生成

今天在看Spring Cloud Config,配置时使用自己虚拟机上搭建的git,结果一直报错,查了好久终于解决了。

pom.xml 加上下面的配置

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

启动类上加上 @EnableConfigServer 注解

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

application.yml

server:
  port: 8087
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8081/eureka/
spring:
  application:
    name: config-server
  cloud:
    config:
      label: master # 配置仓库的分支
      server:
        git:
          uri: qinwei@ip:/home/qinwei/git/repositories/test.git # 配置git仓库地址
          search-paths: config # 配置仓库路径
          #username: 访问git仓库的用户名,(username和password必须配对使用,否则会报错,代码中写的)
          #password: 访问git仓库的密码
          passphrase: qinwei # 访问ssh私钥口令
          ignore-local-ssh-settings: true # If true, use property based SSH config instead of file based.
          private-key: |
                        你的ssh私钥

注意:
如果使用的是 Git SSH configuration,必须要配置 ignore-local-ssh-settings: trueprivate-key !!!
private-key 要注意 是在 | 后加上你的ssh私钥,不然也会报错(私钥在C:Users你的用户名.ssh文件下,id_rsa)

在网上看了好久都是没用的,最后在官网上才找到了原因,还是官网上靠谱啊。
http://cloud.spring.io/spring-cloud-static/Edgware.RELEASE/single/spring-cloud.html#_git_ssh_configuration_using_properties

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值