Spring cloud config 使用gitHub或者gitee连接

1. 创建SpringCloud项目,引入对应的Spring-config-server对应的jar

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jgit</groupId>
            <artifactId>org.eclipse.jgit</artifactId>
            <version>3.7.1.201504261725-r</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-actuator</artifactId>
        </dependency>

 2. 创建一个Spring boot启动类:

添加如下两个注解

@EnableConfigServer
@SpringBootApplication
package cn.lonecloud.config.server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

/**
 * @author lonecloud
 * @version v1.0
 * @Package cn.lonecloud.config
 * @Description: TODO
 * @date 2018/6/12下午7:58
 */
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class,args);
    }
}

  

3. 添加application.yml

由于连接git分两种:一种为共有没有访问权限密码的,一种使用账号密码登录,一种采用ssh登录,

(一).完全公开,无密码访问配置:

server:
  port: 3344 #设置端口
spring:
  application:
    name: config-server #设置名称
  cloud:
    config:
      server:
        git:
          uri: git@gitee.com:lonecloud/xxx.git #设置git仓库地址
          force-pull: true #设置强行pull拉取

(二).采用账号密码访问登录

server:
  port: 3344 #设置端口
spring:
  application:
    name: config-server #设置名称
  cloud:
    config:
      server:
        git:
          uri: git@gitee.com:lonecloud/xxx.git #设置git仓库地址
          force-pull: true #设置强行pull拉取
          username: lonecloud
          password:  password #填写你自己密码

(三).采用SSH无密码登录,最坑的则是第三个,如果您的主机配置了ssh则直接采用(一)方案即可,如果没有配置则需要生成对应的ssh key,将其复制到此处,既可访问

server:
  port: 3344
spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: git@gitee.com:lonecloud/xxx.git
          ignoreLocalSshSettings: true
          force-pull: true
          privateKey: |   #这个地方复制你的RSA密码,记得这里有个| 别忘了
                      -----BEGIN RSA PRIVATE KEY-----
                      
                      -----END RSA PRIVATE KEY-----

  

4. 直接访问该地址,由于我的配置地址为3344端口,所以我的地址为http://localhost:3344/application-dev.yml

后面的参数为{你的git上的文件名}-{profile}.yml

profile,这就是你在你的配置文件中设置的配置文件分类,用于分别你的事dev环境还是test环境

 

有问题欢迎加入群:416052025。交流

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值