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: [email protected]:lonecloud/xxx.git #设置git仓库地址
          force-pull: true #设置强行pull拉取

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

server:
  port: 3344 #设置端口
spring:
  application:
    name: config-server #设置名称
  cloud:
    config:
      server:
        git:
          uri: [email protected]: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: [email protected]: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。交流

原文地址:https://www.cnblogs.com/lonecloud/p/9189407.html

时间: 2024-08-30 16:45:26

Spring cloud config 使用gitHub或者gitee连接的相关文章

跟我学SpringCloud | 第六篇:Spring Cloud Config Github配置中心

SpringCloud系列教程 | 第六篇:Spring Cloud Config Github配置中心 Springboot: 2.1.6.RELEASE SpringCloud: Greenwich.SR1 如无特殊说明,本系列教程全采用以上版本 随着分布式项目越来越大,勤劳的程序猿们会开始面临一个挑战,配置文件会越来越繁杂,虽然spring提供了一个鸡肋版的解决方案,spring.profiles.active,在大型的分布式项目体系中,聊胜于无吧,手动维护配置文件的痛苦,生产,UAT,测

Spring Cloud Config采用数据库存储配置内容

在之前的<Spring Cloud构建微服务架构:分布式配置中心>一文中,我们介绍的Spring Cloud Server配置中心采用了Git的方式进行配置信息存储.这一设计巧妙的利用Git自身机制以及其他具有丰富功能的Git服务端产品,让Spring Cloud Server在配置存储和管理的上避开了很多与管理相关的复杂实现,使其具备了配置中心存储配置和读取配置的基本能力:而更上层的管理机制,由于不具备普遍适用性,所以Spring Cloud Server并没有自己去实现这部分内容,而是通过

Spring Cloud Config 入门

1.    简介 Spring Cloud Config 是用来为分布式系统中为微服务应用提供集中化的外部配置支持,主要分为Spring Cloud Config Server(服务器端)和Spring Cloud Config Client(客户端). 2.    Spring Cloud Config Server Spring Cloud Config Server为服务器端,它是一个单独的微服务应用,用来连接配置仓库(本文使用的是git仓库)并为客户端获取配置信息. 1.     首先,

Spring Cloud搭建手册(2)——Spring Cloud Config

※在Dalston.SR2版本以后,均不能正常加密,如果必须使用此功能,需要降级到SR1或Camden SR7. 1.首先需要创建一个config-server工程,作为配置中心的服务器,用来与git.svn或者本地仓库连接,从仓库获取配置文件 ① config-server工程的POM文件需要增加以下依赖: <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>sprin

spring cloud 入门系列七:基于Git存储的分布式配置中心--Spring Cloud Config

我们前面接触到的spring cloud组件都是基于Netflix的组件进行实现的,这次我们来看下spring cloud 团队自己创建的一个全新项目:Spring Cloud Config.它用来为分布式系统中的基础设施和微服务提供集中化的外部配置支持,分为服务端和客户端两个部分. 其中服务端也称为分布式配置中心,他是独立的微服务应用,用来连接配置仓库并为客户端提供获取接口(这些接口返回配置信息.加密.解密信息等): 客户端是微服务架构中的各个微服务应用或基础设施,它们通过制定的配置中心来管理

Spring Cloud Config 配置中心

1.构建config-server 创建一个pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://

Spring Cloud Config分布式配置中心的使用和遇到的坑

分布式配置中心 为什么要有用分布式配置中心这玩意儿?现在这微服务大军已经覆盖了各种大小型企业,每个服务的粒度相对较小,因此系统中会出现大量的服务,每个服务都要有自己都一些配置信息,或者相同的配置信息,可能不同环境每个服务也有单独的一套配置,这种情况配置文件数量比较庞大,维护起来相当费劲,举个栗子: 在开发的过程中,一般数据库是开发环境数据库,所有服务DB的IP配置为:92.168.0.1,突然老大说,开发环境换了,DB的IP要修改,这下可不好受了,所有模块挨个修改DB的配置,就问你难受不难受?

Spring Cloud Config git版

由于在学习这块内容的时候还不会使用gitHub所以就用了osc的码云 config server POM文件 <dependency>   <groupId>org.springframework.cloud</groupId>   <artifactId>spring-cloud-config-server</artifactId></dependency> git版配置文件 spring: application:   name:

Spring Cloud(八)高可用的分布式配置中心 Spring Cloud Config

在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程Git仓库中.在spring cloud config 组件中,分两个角色,一是config server,二是config client,业界也有些知名的同类开源产品,比如百度的disconf. 相比较同类产品,SpringCloudConfig