Spring Cloud实践之集中配置Spring-config
将一个系统中各个应用的配置文件集中起来,方便管理。
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication
@EnableConfigServer
public class ConfigApplication { public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
如上,对一个spring boot应用加上@EnableConfigServer就可以将其变成一个集中配置服务。
build.gradle文件:
buildscript {
ext {
springBootVersion = '1.4.2.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
mavenCentral()
maven { url "http://dl.bintray.com/oembedler/maven" }
maven { url "https://repo.spring.io/libs-release" }
maven { url "http://10.100.122.249:8881/nexus/content/groups/public/" }
}
dependencyManagement {
imports {
//mavenBom 'org.springframework.cloud:spring-cloud-netflix:1.2.0.M1'
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR2'
}
}
dependencies {
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-config-server
compile("org.springframework.cloud:spring-cloud-starter-parent:Camden.SR2")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.cloud:spring-cloud-config-server")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-actuator")
}
config server自己的配置文件如下:
spring:
cloud:
config:
server:
native:
searchLocations: classpath:/shared
profiles:
active: native server:
port: 8888 security:
user:
password: root
native代表将各个接入应用的配置文件放在config server的本地目录,这里放在classpath:/shared ;并对接入应用开启验证,用户名user密码root;
启动config server,验证http://localhost:8888/demo/application.property (这里假设在shared目录放入了demo应用的配置文件demo.property) 再来看看接入应用如何使用这个config server
在demo应用中:
//在dependencies中加入
compile("org.springframework.cloud:spring-cloud-starter-parent:Camden.SR2")
compile("org.springframework.cloud:spring-cloud-starter-config")
//在build.gradle根下加入如下依赖项
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Camden.SR2'
}
}
* 将项目resource下application.properties文件复制到server-config resource下的shared文件夹中
并重命名为项目名.properties,如demo项目,命名为demo.properties
* 清空application.properties内容
3. 在resource下新建bootstrap.yml文件(以demo项目举例)
spring:
application:
name: demo
profiles:
active: default
cloud:
config:
uri: http://localhost:8888/
name: demo
fail-fast: true
password: root
username: user
Spring Cloud实践之集中配置Spring-config的更多相关文章
- Spring Cloud 系列之 Consul 配置中心
前面我们已经学习过 Spring Cloud Config 了: Spring Cloud 系列之 Config 配置中心(一) Spring Cloud 系列之 Config 配置中心(二) Spr ...
- Spring Cloud 系列之 Apollo 配置中心(三)
本篇文章为系列文章,未读前几集的同学请猛戳这里: Spring Cloud 系列之 Apollo 配置中心(一) Spring Cloud 系列之 Apollo 配置中心(二) 本篇文章讲解 Apol ...
- Spring Cloud 系列之 Apollo 配置中心(四)
本篇文章为系列文章,未读前几集的同学请猛戳这里: Spring Cloud 系列之 Apollo 配置中心(一) Spring Cloud 系列之 Apollo 配置中心(二) Spring Clou ...
- Spring Cloud 入门教程 - 搭建配置中心服务
简介 Spring Cloud 提供了一个部署微服务的平台,包括了微服务中常见的组件:配置中心服务, API网关,断路器,服务注册与发现,分布式追溯,OAuth2,消费者驱动合约等.我们不必先知道每个 ...
- Spring Cloud:多环境配置、eureka 安全认证、容器宿主机IP注册
记录一下搭建 Spring Cloud 过程中踩过的一些坑,测试的东西断断续续已经弄了好多了,一直没有时间整理搭建过程,时间啊~时间~ Spring 版本 Spring Boot:2.0.6.RELE ...
- spring cloud连载第二篇之Spring Cloud Config
Spring Cloud Config Spring Cloud Config为分布式服务提供了服务侧和客户侧的外部配置支持.通过Spring Cloud Config你可以有一个统一的地方来管理所有 ...
- Spring Cloud(九):分布式配置中心和消息总线
我们在Spring Cloud(七):使用SVN存储分布式配置中心文件和实现refresh中讲到,如果需要客户端获取到最新的配置信息需要执行refresh,我们可以利用webhook的机制每次提交代码 ...
- Spring Cloud 基于Consul 实现配置服务
Spring Cloud体系中提供了Config组件来进行配置服务管理.而Consul除了提供服务注册与发现功能外,同时也提供配置管理功能.本位将介绍如何结合Spring Cloud + Consul ...
- spring cloud深入学习(十)-----配置中心和消息总线(配置中心终结版)
如果需要客户端获取到最新的配置信息需要执行refresh,我们可以利用webhook的机制每次提交代码发送请求来刷新客户端,当客户端越来越多的时候,需要每个客户端都执行一遍,这种方案就不太适合了.使用 ...
随机推荐
- 通过脚本命令cacls提升某个用户都某路径的操作权限
摘要----项目需要对服务器上的某个路径下的目录,修改权限:给Users用户组的用户添加修改写入权限. 原理----通过批处理脚本实现,命令使用 icacls 修改ACL 来达到修改权限的目的. 操作 ...
- Nodejs+Mongo+WebAPI
Nodejs+Mongo+WebAPI集成 1.[ 目录]: |- models/bear.js |- node_modules/ |- express |- mongoose |- body-par ...
- 【Linux】DNS基础(一)
DNS基础 DNS 是计算机域名系统 (Domain Name System 或Domain Name Service) 的缩写,域名服务器是进行域名(domain name)和与之相对应的IP地址 ...
- /bin/sh^M:bad interpreter:
/bin/sh^M:bad interpreter: No such file or directory 这个错误发生在你在windows下编写文件上传到linux服务器去运行的时候. 错误原因:wi ...
- 旅行家的预算(NOIP1999&水题测试2017082301)
题目链接:旅行家的预算 这题还可以,不算太水. 这题贪心即可. 我们采取如下动作: 如果在装满油的情况下能到达的范围内,没有加油站,则无解. 如果在装满油的情况下能到达的范围内,油价最低的加油站的油价 ...
- 数据分析处理库pandas及可视化库Matplotlib
一.读取文件 1)读取文件内容 import pandas info = pandas.read_csv('1.csv',encoding='gbk') # 获取文件信息 print(info) pr ...
- hdu6365 2018 Multi-University Training Contest 6 1004 Shoot Game
http://acm.hdu.edu.cn/showproblem.php?pid=6365 细节处理 unique返回的是最后一位的后一位,因此从1开始的数组要减去(p+1) 结构体可以用unqiu ...
- error C4430: error 2141
c:\evan\workspace\1\1\netwowkippack.h(50) : error C2146: 语法错误 : 缺少“;”(在标识符“nSourPort”的前面) c:\evan\wo ...
- 微信小程序两种滑动方式
竖向滑动: <scroll-view scroll-y="true" style="height: 200rpx;"> <view style ...
- ajax实现
AJAX是为了实现异步通信,提高用户体验度.JavaScript本身并不具有向服务器发送请求的功能(不使用NodeJs),要么使用window.open()方法重新打开一个页面向服务器发送请求,要么使 ...