配置中心作为springcloud里最底层的框架,所发挥的意思是举足轻重的,所以的组件的配置信息都可以通过springcloud config来管理,它会把配置信息分布式的存储到git上,所以信息安全这块可以放心,其它应用程序在更新配置时,直接在远程GIT仓库更新即可,而且更新后自动同步到对应的程序里,不需要重启这个应用程序!

配置服务-服务端,最底层应用

依赖包

dependencies {
compile('org.springframework.cloud:spring-cloud-config-server',
'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server'
)
testCompile('org.springframework.boot:spring-boot-starter-test')
}

配置项

server:
port: 8200
spring:
application:
name: lind-config-server
cloud:
config:
server:
git:
uri: https://github.com/bfyxzls/lindconfig.repo.git/
search-paths: config-repo
username: bfyxzls@sina.com
password: 纟
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.application.name}:${server.port}
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/

启动代码

@EnableDiscoveryClient
@EnableConfigServer
@SpringBootApplication
class Application { public static void main(String[] args) {
// demo http://localhost://8200/email-svt.yml
SpringApplication.run(Application.class, args);
}
}

在github上添加对应的仓库,客户端的配置文件将会同步到GIT仓库,建议配置文件采用yml语法!

/****************************************************************************************
* 配置服务的路劲规则:
*
* /{application}/{profile}[/{label}]
* /{application}-{profile}.yml
* /{label}/{application}-{profile}.yml
* /{application}-{profile}.properties
* /{label}/{application}-{profile}.properties
****************************************************************************************/

仓储如图:

查看配置中心服务端是否正常

访问:http://localhost:8200/email-svt.yml

配置中心-客户端,遍及在所有应用中

依赖包

dependencies {
compile('org.springframework.boot:spring-boot-starter-web',
'org.springframework.cloud:spring-cloud-starter-config',
'org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

配置项

spring:
application:
name: email #注意这里的email是指配置中心git仓库里yml文件的application的部分
cloud:
config:
uri: http://localhost:8200
server:
port: 8300 eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/

启动项

@EnableEurekaClient
@SpringBootApplication
public class Application { public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

我们可以在客户端使用$Value注解完成配置文件的读取!

@RestController
public class HomeController {
@Value("${server.port}") // git配置文件里的key
String serverPort; @RequestMapping("/")
public String index() {
return "serverPort=" + serverPort;
}
}

结果如图:

感谢各位的阅读!

springcloud~配置中心的使用的更多相关文章

  1. SpringCloud配置中心实战

    SpringCloud配置中心实战 1.统一配置中心(Config) 1.1 Spring项目配置加载顺序 1.2 配置规则详解 1.3 Git仓库配置 1.3.1 使用占位符 1.3.2 模式匹配 ...

  2. springcloud配置中心

    SpringCloud Config简介 Spring Cloud Config 是 Spring Cloud 团队创建的一个全新项目,用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持 ...

  3. Consul作为SpringCloud配置中心

    一.背景介绍 在分布式系统中动态配置中,可以避免重复重启服务,动态更改服务参数等.一句话非常重要. 另外一篇文章也是这样说的,哈哈. Consul 作为Spring 推荐的分布式调度系统其也具备配置中 ...

  4. SpringCloud配置中心config

    1,配置中心可以用zookeeper来实现,也可以用apllo 来实现,springcloud 也自带了配置中心config Apollo 实现分布式配置中心 zookeeper:实现分布式配置中心, ...

  5. springcloud~配置中心实例搭建

    server端 build.gradle相关 dependencies { compile('org.springframework.cloud:spring-cloud-config-server' ...

  6. springcloud配置中心客户端配置遇到的坑

    1. 出错信息如下: 在启动配置中心的客户端时,报以下错误信息: Caused by: java.lang.IllegalArgumentException: Could not resolve pl ...

  7. SpringCloud配置中心集成Gitlab(十五)

    一 开始配置config服务 config-server pom.xml <dependency> <groupId>org.springframework.cloud< ...

  8. springcloud~配置中心~对敏感信息加密

    简介 RSA非对称加密有着非常强大的安全性,HTTPS的SSL加密就是使用这种方法进行HTTPS请求加密传输的.因为RSA算法会涉及Private Key和Public Key分别用来加密和解密,所以 ...

  9. springcloud(七):配置中心svn示例和refresh

    上一篇springcloud(六):配置中心git示例留了一个小问题,当重新修改配置文件提交后,客户端获取的仍然是修改前的信息,这个问题我们先放下,待会再讲.国内很多公司都使用的svn来做代码的版本控 ...

随机推荐

  1. selenium+java破解极验滑动验证码的示例代码

    转自: https://www.jianshu.com/p/1466f1ba3275 selenium+java破解极验滑动验证码 卧颜沉默 关注 2017.08.15 20:07* 字数 3085  ...

  2. IntelliJ IDEA 配置maven

    以下内容引自http://blog.csdn.net/qq_32588349/article/details/51461182. 使用IntelliJ IDEA 配置Maven(入门)         ...

  3. 打开office时提示错误窗口“向程序发送命令时出现问题”的解决方案

    今天同事问了我一件很怪异的事情,说她的office打不开了,如打开word或excel时,突然出现错误提示错误窗口"向程序发送命令时出现问题",分析原因才知道她安装了 AVG pc ...

  4. timeCache.go

    package blog4go import ( "sync" "time" ) const ( // PrefixTimeFormat  时间格式前缀 Pre ...

  5. Semaphore简介

    Semaphore简介 Semaphore是并发包中提供的用于控制某资源同时被访问的个数 操作系统的信号量是个很重要的概念,在进程控制方面都有应用.Java 并发库 的Semaphore 可以很轻松完 ...

  6. ArcGIS API for JavaScript 入门教程[1] 渊源

    ->对于萌新,你可能需要了解一下这个东西是什么 ->对于已经知道要用这个东西的开发者,你可能需要了解一下它的底层机制 不针对大牛.龟速更新ing. 转载注明出处.博客园&CSDN& ...

  7. 用Python学分析 - 二项分布

    二项分布(Binomial Distribution)对Bernoulli试验序列的n次序列,结局A出现的次数x的概率分布服从二项分布- 两分类变量并非一定会服从二项分布- 模拟伯努利试验中n次独立的 ...

  8. 深度学习之卷积神经网络(CNN)

    卷积神经网络(CNN)因为在图像识别任务中大放异彩,而广为人知,近几年卷积神经网络在文本处理中也有了比较好的应用.我用TextCnn来做文本分类的任务,相比TextRnn,训练速度要快非常多,准确性也 ...

  9. 【工具篇】Selenium 学习实践(一)环境搭建

    一.环境搭建 (1)初学者最佳环境: Python 2.7 + Selenium 2+ Firefox 46 (2)喜欢尝新的环境: Python 3.6 + Selenium 3+ Firefox ...

  10. 同源策略 & 高效调试CORS实现

    # 目录 为什么有同源策略? 需要解决的问题 CORS跨域请求方案 preflight withCredentials 附:高效.优雅地调试CORS实现 ----------------------- ...