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。交流

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

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

    SpringCloud系列教程 | 第六篇:Spring Cloud Config Github配置中心 Springboot: 2.1.6.RELEASE SpringCloud: Greenwic ...

  2. 为Spring Cloud Config插上管理的翅膀

    最近一致在更新Spring Cloud Config的相关内容,主要也是为这篇埋个伏笔,相信不少调研过Spring Cloud Config的用户都会吐槽它的管理能力太弱.因此,就有了下面为讲推荐的这 ...

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

    在之前的<Spring Cloud构建微服务架构:分布式配置中心>一文中,我们介绍的Spring Cloud Server配置中心采用了Git的方式进行配置信息存储.这一设计巧妙的利用Gi ...

  4. Spring Cloud官方文档中文版-Spring Cloud Config(上)

    官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#spring-cloud-feign 文中例子我做了一些测试在:http ...

  5. Spring Cloud官方文档中文版-Spring Cloud Config(下)-客户端等

    官方文档地址为:http://cloud.spring.io/spring-cloud-static/Dalston.SR2/#_serving_alternative_formats 文中例子我做了 ...

  6. SpringCloud(6)分布式配置中心Spring Cloud Config

    1.Spring Cloud Config 简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组 ...

  7. Spring Cloud Config采用Git存储时两种常用的配置策略

    由于Spring Cloud Config默认采用了Git存储,相信很多团队在使用Spring Cloud的配置中心时也会采用这样的策略.即便大家都使用了Git存储,可能还有各种不同的配置方式,本文就 ...

  8. Spring Cloud Config(配置中心)

    每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 一.简介 Spring Cloud Config为分布式系统中的外部配置提供服务器和客 ...

  9. 【八】Spring Cloud Config

    一.分布式系统面临的--配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的力度相对较小,因此系统中会出现大量的服务.由于每个服务都需要必要的配置信息才能运行,所以一套集中式的.动 ...

随机推荐

  1. 容错处理try

    var num = 90; try{ console.log( num + 100 ); consolel.log(aaa); }catch(e){ console.log("如果程序中有异 ...

  2. WPF中任务栏只显示主窗口

    我们在用WPF开发的时候,常常会遇到在主窗口打开的情况下,去显示子窗口,而此时任务栏同时显示主窗口与子窗口.这样看起来很不美观.所以在弹出子窗口之前,设置它的几个相应属性,便不会出现这种问题了. // ...

  3. Azure系列2.1.4 —— BlobInputStream

    (小弟自学Azure,文中有不正确之处,请路过各位大神指正.) 网上azure的资料较少,尤其是API,全是英文的,中文资料更是少之又少.这次由于公司项目需要使用Azure,所以对Azure的一些学习 ...

  4. Python基础知识2-内置数据结构(下)

    bytes.bytearray #思考下面例子: a = 1 b = a print(a == b)#True print(a is b)#True print(id(a) is id(b))#Fal ...

  5. python3 自动识图

    一.安装依赖库 pip install pytesseract pip install pillow 二.安装识图引擎tesseract-ocr https://pan.baidu.com/s/1Qa ...

  6. spring 标签

    */ @Slf4j @Service public class RetryService { @Autowired private MqConfig mqConfig; /** * 如果网络连接失败, ...

  7. 老男孩python学习自修第十五天【常用模块之time】

    例如: #!/usr/bin/env python # _*_ coding:UTF-8 _*_ import time if __name__ == "__main__": pr ...

  8. AVL树,红黑树

    AVL树 https://baike.baidu.com/item/AVL%E6%A0%91/10986648 在计算机科学中,AVL树是最先发明的自平衡二叉查找树.在AVL树中任何节点的两个子树的高 ...

  9. 待解决ava.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Method)

    java.lang.OutOfMemoryError: PermGen space at java.lang.ClassLoader.defineClass1(Native Method) at ja ...

  10. windows下ping端口

    上图的操作完成以后  进入dos控制台 输入telnet  ip地址  端口号   回车 标识已ping通 ping不通是这种提示