package com.itmuch.cloud;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class ConfigClientController { @Value("${profile}")
private String profile; //可以获取本地application.yml配置文件profile: ssss的值 @GetMapping("/profile")
public String getProfile() {
System.out.println(this.profile);
return this.profile;
}
}
package com.itmuch.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}

application.yml

server:
port: 8081 # profile: ssss # 通过localhsot:8081/profile就可以访问到config server里面的配置,如果本地有profile属性就加载本地的profile属性
#

bootstrap.yml

# springcloud里面有一个启动上下文,用来加载远端的配置就是config server里面的配置
# 先加载bootstrap.yml加载config server里面的配置,然后去加载application.yml里面的配置
#
spring:
cloud:
config:
uri: http://localhost:8080 #config server的端口
profile: dev
label: master # 当configserver的后端存储是Git时,默认就是master
application:
name: foobar #本工程的名字,去config server的git仓库里面找foobar-dev.yml文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.itmuch.cloud</groupId>
<artifactId>microservice-spring-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent> <artifactId>microservice-config-client</artifactId>
<packaging>jar</packaging> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<!-- config client依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<!-- springmvc依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies> </project>

package com.itmuch.cloud;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}

application.yml

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video
username:
password: # git里面 foobar-dev.yml内容profile: profile-dev,给工程foobar使用的。
# git里面application.yml内容profile: profile-default,档foobar工程找不到foobar-dev.yml时候使用。

application.yml.bak1-基础使用方式

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video

application.yml.bak2-通配符

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/{application}

application.yml.bak3-模式匹配

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video # 公用
repos:
simple: https://git.oschina.net/it-much/simple
special:
pattern: special*/dev*,special*/test*
uri: https://git.oschina.net/it-much/special

application.yml.bak4-搜索路径

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video # 公用
search-paths:
- foo # foo路径
- bar # bar路径

application.yml.bak5-cloneOnStart

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video # 公用
clone-on-start: true
repos:
simple: https://git.oschina.net/it-much/simple
special:
pattern: special*/dev*,special*/test*
uri: https://git.oschina.net/it-much/special
cloneOnStart: false

application.yml.bak6-账号密码

server:
port: 8080
spring:
cloud:
config:
server:
git:
uri: https://git.oschina.net/it-much/config-repo-51cto-video
username:
password:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <parent>
<groupId>com.itmuch.cloud</groupId>
<artifactId>microservice-spring-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent> <artifactId>microservice-config-server</artifactId>
<packaging>jar</packaging> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<!-- config server依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency> </dependencies> </project>

springcloud18---springCloudConfig的更多相关文章

  1. SpringCloud-config分布式配置中心

    为什么要统一管理微服务配置? 随着微服务不断的增多,每个微服务都有自己对应的配置文件.在研发过程中有测试环境.UAT环境.生产环境,因此每个微服务又对应至少三个不同环境的配置文件.这么多的配置文件,如 ...

  2. SpringCloudConfig配置中心git库以及refresh刷新

    基于git库的Spring Cloud Config配置中心代码demo下载地址:https://gitlab.com/mySpringCloud/config-git SpringBoot版本: 1 ...

  3. SpringCloud系列十:SpringCloudConfig 高级配置(密钥加密处理(JCE)、KeyStore 加密处理、SpringCloudConfig 高可用机制、SpringCloudBus 服务总线)

    1.概念:SpringCloudConfig 高级配置 2.具体内容 在 SpringCloudConfig 之中考虑到所有配置文件都暴露在远程仓库之中的安全性问题,所以提供有安全访问的处理机制,这样 ...

  4. SpringCloud系列九:SpringCloudConfig 基础配置(SpringCloudConfig 的基本概念、配置 SpringCloudConfig 服务端、抓取配置文件信息、客户端使用 SpringCloudConfig 进行配置、单仓库目录匹配、应用仓库自动选择、仓库匹配模式)

    1.概念:SpringCloudConfig 基础配置 2.具体内容 通过名词就可以发现,SpringCloudConfig 核心作用一定就在于进行配置文件的管理上.也就是说为了更好的进行所有微服务的 ...

  5. spring-cloud-config——Quick Start

    参考资料: https://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.0.RELEASE/single/spring-cl ...

  6. 六:SpringCloud-Config

    十:SpringCloudConfig分布式配置中心 1. 概述 1.1 分布式系统面临的 配置问题 微服务意味着要将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中会出现大量的 ...

  7. spring-cloud-config笔记

    忽略元数据末尾 回到原数据开始处 spring-cloud-config 简单来讲就是spring-cloud实现的分布式配置中心.与之前介绍的开源配置服务方案 disconf是一样的,spring- ...

  8. spring-cloud-config 配置中心快速上手

    spring-cloud-config 配置中心实现 Spring Cloud Config 用于为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,分为server端和client端. s ...

  9. springcloud学习之路: (五) springcloud集成SpringCloudConfig分布式配置中心

    SpringCloud全家桶中的分布式配置中心SpringCloudConfig, 它使用git来管理配置文件, 在修改配置文件后只需要调用一个接口就可以让新配置生效, 非常方便. SpringClo ...

  10. SpringCloud-Config通过Java访问URL对敏感词加密解密

    特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...

随机推荐

  1. VS2015编译CURL7.54.0源码

    2018.8.24找到一种新途径,运行curl-master\projects\generate.bat,然后curl-master\projects\Windows\VC14\curl-all.sl ...

  2. [020]Sencha Ext JS 6.0使用教程2

    本节主要以典型例子介绍如何用Sencha Ext JS6.0进行项目开发 入门阶段总是比较难的,掌握了基本操作步骤,使用方法,架构思维,开发起来还是满顺利,开心的,自己又能掌握一门新技术,又能进步,主 ...

  3. Apktool源码解析——第一篇

    著名的apktool是android逆向界用的最普遍的一个工具,这个项目的原始地址在这里http://code.google.com/p/android-apktool/,但是你们都懂的在天朝谷歌是无 ...

  4. AndroidWear开发之开发环境[前奏]

    上篇教程教的是如何下载最新的SDK http://www.cnblogs.com/bvin/p/3811751.html 一.Eclipse下的尝试 之前以为在Eclipse下把SDK,ADT更新一下 ...

  5. MQTT的学习研究(二)moquette-mqtt 的使用之mqtt broker的启动

    在MQTT 官网 (http://mqtt.org/software)中有众多MQTT的实现方式.具体参看官网,Moquette是基于Apache Mina 的模型的一个Java MQTT broke ...

  6. JavaWeb温习之HttpServletResponse对象

    以下内容均根据"方立勋JavaWeb视频教程"进行总结 1. HttpServletResponse常见应用——设置响应头控制浏览器的行为 1.1 设置http响应头控制浏览器禁止 ...

  7. 9.Node.js 包管理器npm

    npm 是 Node.js  官方提供的包管理工具, 用于 Node.js包的发布.传播.依赖控制 安装 express ==> 流行的基于Node.js的Web开发框架,可以快速地搭建一个完整 ...

  8. Windows Phone 自定义一个启动画面

    1.新建一个UserControl <UserControl x:Class="LoadingPage.PopupSplash" xmlns="http://sch ...

  9. python之xlwt模块列宽width、行高Heights详解

    今天用python操作excel时,发现xlwt的API中没有对width.height有更多介绍,且使用时也不知道width取多少合适.现在这做个详细介绍 使用版本: python:2.7.5 xl ...

  10. reflect 机制

    1: Class.forName的作用?为什么要用? 答:调用该访问返回一个以字符串指定类名的类的对象. 2: 通过反射,有几种方法可以实例化Class类对象? 3种,第一种:Class.forNam ...