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. VS2015 + OPENCV + CUDA 安装流程

    VS2015  https://blog.csdn.net/guxiaonuan/article/details/73775519?locationNum=2&fps=1 OPENCV htt ...

  2. Mac 在terminal 上用命令打开sublime

    Step1. 安装Sublime Text编辑器 可直接到以下网址下载dmg安装文件: Sublime Text 3 Step2. 添加命令行别名 打开用户配置文件 vim ~/.bash_profi ...

  3. 初次启动hive,解决 ls: cannot access /home/hadoop/spark-2.2.0-bin-hadoop2.6/lib/spark-assembly-*.jar: No such file or directory问题

    >>提君博客原创  http://www.cnblogs.com/tijun/  << 刚刚安装好hive,进行第一次启动 提君博客原创 [hadoop@ltt1 bin]$ ...

  4. 转《service worker在移动端H5项目的应用》

    1. PWA和Service Worker的关系 PWA (Progressive Web Apps) 不是一项技术,也不是一个框架,我们可以把她理解为一种模式,一种通过应用一些技术将 Web App ...

  5. mapreduce join

    MapReduce Join 对两份数据data1和data2进行关键词连接是一个很通用的问题,如果数据量比较小,可以在内存中完成连接. 如果数据量比较大,在内存进行连接操会发生OOM.mapredu ...

  6. python之路-字符串

    一.类型转换 a = 10 print(type(a)) # <class 'int'> d = str(a) # 把数字转换成str print(type(d)) # <class ...

  7. AspectJ用注解替换xml配置

    AspectJ基于注解的使用 AspectJ简介 AspectJ是一个基于Java语言的AOP框架,一般 其主要用途:自定义开发 一般情况下spring自动生成代理,要配置aop, 首先确定目标类,a ...

  8. Laravel从入门到精通

    1. Laravel框架的下载安装 例如: 在D:\test\laravel目录下新建一个目录为test_laravel 第一步,下载laravel框架 在D:\test\laravel\test_l ...

  9. js外部调用layui.use中的函数的写法

    layui模块化的写法固然不错,但也有让人不适应的一些地方 外部调用函数的写法就让人不太舒服 需要在函数名前面加上window这个前缀,就不太舒服 补充:window前缀,是全局变量的声明方式 如下: ...

  10. python排序 sorted()与list.sort() (转)

    该文章为转载:原文地址为:https://www.cnblogs.com/zuizui1204/p/6422939.html 只要是可迭代对象都可以用sorted . sorted(itrearble ...