SpringCloud之搭建配置中心
一、搭建config-server
1、引入pom
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<!-- 配置中心服务端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!-- Rabbitmq模块 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<!-- 解决启动报Caused by: java.lang.ClassNotFoundException: org.eclipse.jgit.api.TransportConfigCallback -->
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>4.9.0.201710071750-r</version>
</dependency>
</dependencies>
2、配置文件
application.properties
spring.profiles.active=@environment@ # 应用名称
spring.application.name=crm-config-server
# 服务端口
server.port=21200 # 禁用actuator管理端鉴权
management.security.enabled=false
# 启用shutdown host:port/shutdown
endpoints.shutdown.enabled=true
# 禁用密码验证
endpoints.shutdown.sensitive=false
application-local.yml
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:20000/eureka/
instance:
lease-renewal-interval-in-seconds: 10
lease-expiration-duration-in-seconds: 30
preferIpAddress: true
spring:
cloud:
config:
server:
git:
uri: http://gitlab.xxx.com/crm/crm-config-repo.git
username: xxx
password: 'RHqGz$N31'
# 这里可以写死,也可以写成{profile}来动态化
search-paths: local
rabbitmq:
addresses: amqp://10.18.75.231:5672
username: user_admin
password: 222
virtual-host: crm
3、Application.java
package com.tomato.crm.config; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication
@EnableConfigServer
public class CrmConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(CrmConfigServerApplication.class, args);
}
}
通过属性:spring.profiles.active 来控制不同环境不同的配置文件(git路径不同)
二、配置仓库
采用分功能(例如数据库的、redis的)、分项目的形式进行划分配置文件
三、具体的项目(config client)
1、引入pom
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
2、bootstrap.properties
spring.application.name=crm-security-service
server.port=
# 默认为local,可以通过启动参数来赋值进行覆盖
spring.profiles.active=local
# 非本地的启动,注册中心采用启动参数传入,本地测试也在启动参数中注入
# 此参数请勿放开并提交,因为bootstrap的优先级最高(高于启动参数),这里不能写死
#eureka.client.serviceUrl.defaultZone=http://127.0.0.1:20000/eureka/ # 配置中心配置
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.service-id=crm-config-server
# 分支, 默认master
spring.cloud.config.label=master
# 环境,如果配置了则会去读取common.properties + common-local.properties/yml
# spring.cloud.config.profile=local
spring.cloud.config.name=common,bus,redis,security-service
这里采用通过注册中心获取config server的形式来做多实例负载均衡。
四、配置刷新
方法1:
post请求需要刷新的服务的Endpoint是:/refresh
方法2:
通过配置中心发起广播(MQ)刷新:手动post请求到配置中心服务的:/bus/refresh
方法3:
通过git lab的事件机制来post请求方法2中的url
SpringCloud之搭建配置中心的更多相关文章
- Spring Cloud 入门教程 - 搭建配置中心服务
简介 Spring Cloud 提供了一个部署微服务的平台,包括了微服务中常见的组件:配置中心服务, API网关,断路器,服务注册与发现,分布式追溯,OAuth2,消费者驱动合约等.我们不必先知道每个 ...
- 19.SpringCloud实战项目-SpringCloud整合Alibaba-Nacos配置中心
SpringCloud实战项目全套学习教程连载中 PassJava 学习教程 简介 PassJava-Learning项目是PassJava(佳必过)项目的学习教程.对架构.业务.技术要点进行讲解. ...
- springcloud(七):配置中心svn示例和refresh
上一篇springcloud(六):配置中心git示例留了一个小问题,当重新修改配置文件提交后,客户端获取的仍然是修改前的信息,这个问题我们先放下,待会再讲.国内很多公司都使用的svn来做代码的版本控 ...
- springcloud(九):配置中心和消息总线(配置中心终结版)
我们在springcloud(七):配置中心svn示例和refresh中讲到,如果需要客户端获取到最新的配置信息需要执行refresh,我们可以利用webhook的机制每次提交代码发送请求来刷新客户端 ...
- [转]springcloud(九):配置中心和消息总线(配置中心终结版)
https://www.cnblogs.com/ityouknow/p/6931958.html springcloud(九):配置中心和消息总线(配置中心终结版) 我们在springcloud(七) ...
- Spring Cloud Config(三):基于JDBC搭建配置中心
1.简介 本文主要内容是基于jdbc搭建配置中心,使应用从配置中心读取配置信息并成功注册到注册中心,关于配置信息表结构仅供参考,大家可以根据具体需要进行扩展. 2.Config Server 搭建 2 ...
- springcloud费话之配置中心server修改
目录: springcloud费话之Eureka基础 springcloud费话之Eureka集群 springcloud费话之Eureka服务访问(restTemplate) springcloud ...
- springcloud费话之配置中心客户端(SVN)
目录: springcloud费话之Eureka基础 springcloud费话之Eureka集群 springcloud费话之Eureka服务访问(restTemplate) springcloud ...
- springcloud费话之配置中心基础(SVN)
目录: springcloud费话之Eureka基础 springcloud费话之Eureka集群 springcloud费话之Eureka服务访问(restTemplate) springcloud ...
随机推荐
- Curl操作Elasticsearch的常用方法
Elasticsearch对于文档操作,提供了以下几种API,本文就说明如何使用curl方式来调用这些API. API种类 单文档操作API 1.* Index API 索引文档 * 为文档创建索引 ...
- .Net Core配置文件读取整理
一 .配置文件说明 1.配置,主要是 指在程序中使用的一些特殊参数,并且大多数 仅在程序启动的之后指定不需要修改. 2.在以前.Net项目中配置文件主要指app.config或web.config,但 ...
- 深入理解多线程(五)—— Java虚拟机的锁优化技术
本文是<深入理解多线程>的第五篇文章,前面几篇文章中我们从synchronized的实现原理开始,一直介绍到了Monitor的实现原理. 前情提要 通过前面几篇文章,我们已经知道: 1.同 ...
- How to fix Error: listen EADDRINUSE while using nodejs
If I run a server with the port 80, and I try to use xmlHTTPrequest i get this error: Error: listen ...
- spring boot1.5以上版本@ConfigurationProperties取消location注解后的替代方案 cannot resolve method location
问题 在spring boot(版本1.5.1.RELEASE)项目中,当准备映射自定义的配置文件属性到类中的时候,发现原本的@ConfigurationProperties注解已将location属 ...
- Html-文档类型(DTD)和DOCTYPE
在正式介绍文档类型(DTD)和DOCTYPE之前,我们需要先了解HTML和XHTML的之间的区别,现在Html5已经慢慢的成为主流,之前的数十年一直都是Html4.01的天下,Html4.01于199 ...
- Android -- DisplayMetrics
干货 DisplayMetrics dm = new DisplayMetrics(); this.getWindowManager().getDefaultDisplay().getMetrics( ...
- NLP资源
http://www.cs.columbia.edu/~mcollins/notes-spring2013.html http://web.stanford.edu/class/cs224n/syll ...
- sql 根据另一个表的数据更新当前表
--update mchk --set shwdjh=dbo.erpzhong.zhongbz--from erpzhong--where mchk.dwmch=erpzhong.matno
- 推荐一款jQuery ColorPicked 颜色拾取器插件
先看实现的效果图, 本文底部有完整demo 不想看我墨迹的可以跳过了^_^. 官网地址:http://www.eyecon.ro/colorpicker/#about 代码SVN 地址:https:/ ...