Spring Cloud Config 本地配置
七:Spring Cloud Config 本地配置
本地文件系统
我们可以将微服务的相关配置文件存储到本地文件中,然后让微服务来读取本地文件。
创建本地文件 Config Server
1.创建模块,配置环境
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>springCloud01</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>nativeConfigServer</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
</project>
2.配置application.yml
server:
port: 8762
spring:
application:
name: nativeconfigserver
profiles:
active: native
cloud:
config:
server:
native:
search-location: classpath:/shared
3.创建文件夹shared、文件configclient-dev.yml
server:
port: 8070
foo: foo version 1
4.编写启动类
package com.southwind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class nativeServerApplication {
public static void main(String[] args) {
SpringApplication.run(nativeServerApplication.class,args);
}
}
配置中心已经完成
创建客户端
1.创建模块,配置环境
<?xml version="1.0" encoding="UTF-8"?>
<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">
<parent>
<artifactId>springCloud01</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>nativeconfigclient</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
</dependencies>
</project>
2.创建文件
bootstrap.yml
spring:
application:
name: configclient
profiles:
active: dev
cloud:
config:
uri: http://localhost:8762
fail-fast: true
3启动类:
package com.southwind;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class nativeConfigCliehtApplication {
public static void main(String[] args) {
SpringApplication.run(nativeConfigCliehtApplication.class,args);
}
}
4.handler:
package com.southwind.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/native")
public class NativeConfigHandler {
@Value("${server.port}")
private String port;
@Value("${foo}")
private String foo;
@GetMapping("/index")
public String index(){
return this.port+"---"+this.foo;
}
}
Spring Cloud Config 本地配置的更多相关文章
- Spring Cloud Config(配置中心)
每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 一.简介 Spring Cloud Config为分布式系统中的外部配置提供服务器和客 ...
- spring cloud config将配置存储在数据库中
Spring Cloud Config Server最常见是将配置文件放在本地或者远程Git仓库,放在本地是将将所有的配置文件统一写在Config Server工程目录下,如果需要修改配置,需要重启c ...
- 跟我学SpringCloud | 第六篇:Spring Cloud Config Github配置中心
SpringCloud系列教程 | 第六篇:Spring Cloud Config Github配置中心 Springboot: 2.1.6.RELEASE SpringCloud: Greenwic ...
- Spring Cloud Config 实现配置中心,看这一篇就够了
Spring Cloud Config 是 Spring Cloud 家族中最早的配置中心,虽然后来又发布了 Consul 可以代替配置中心功能,但是 Config 依然适用于 Spring Clou ...
- Spring Cloud Config的配置中心获取不到最新配置信息的问题
Spring Cloud Config的配置中心获取不到最新配置信息的问题 http://blog.didispace.com/spring-cloud-tips-config-tmp-clear/
- Spring Cloud Config 分布式配置中心使用教程
一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...
- Spring Cloud Config 分布式配置中心【Finchley 版】
一. 介绍 1,为什么需要配置中心? 当服务部署的越来越多,规模越来越大,对应的机器数量也越来越庞大,靠人工来管理和维护服务的配置信息,变得困难,容易出错. 因此,需要一个能够动态注册和获取服务信息的 ...
- 为Spring Cloud Config Server配置远程git仓库
简介 虽然在开发过程,在本地创建git仓库操作起来非常方便,但是在实际项目应用中,多个项目组需要通过一个中心服务器来共享配置,所以Spring Cloud配置中心支持远程git仓库,以使分散的项目组更 ...
- 重写spring cloud config 本地bootstrap
在spring-cloud中使用了config-server之后,需要在client端加入bootstrap作为配置文件,其中通常包含如下: spring.application.name=ms-as ...
- Spring Cloud Config的配置中心使用非对称性加密
首先,我们需要通过keytool工具来生成密钥对. keytool是JDK中的一个密钥和证书管理工具.它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认 ...
随机推荐
- SpringCloud -Netflix 总结·
springcloud 核心组件 Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册.配置中心.智能路由.消息 ...
- day14 I/O流——序列化与反序列化 & 计算机网络五层架构 & TCP的建立连接与断开连接
day 14 序列化与反序列化 序列化 将对象转化成特定格式的字符串文件(字节文件)叫做序列化 1.一个类要想实现序列化,必须实现serializable接口 2.序列化用途 1)把对象的字节序列 ...
- 数电第一周总结_by_yc
数电第一周总结 重点:Verilog建模方式 结构级建模: 需基于电路原理图 module mux( input data0, input data1, input sel, output out); ...
- 1.2 Hadoop简介-hadoop-最全最完整的保姆级的java大数据学习资料
目录 1.2 Hadoop简介 1.2.1 什么是Hadoop 1.2.2 Hadoop的起源 1.2.3 Hadoop的特点 1.2.4 Hadoop的发行版本 1.2.5 Apache Hadoo ...
- 云原生 • Kubernetes 认识 k8s、k8s 架构、核心概念点介绍
云原生 • Kubernetes 认识 k8s.k8s 架构.核心概念点介绍 一.Kubernetes 简介Kubernetes 简称 k8s,是支持云原生部署的一个平台,起源于谷歌.谷歌早在十几年之 ...
- 帮你短时间拿下Git,Git详细教程(浓缩的都是精华)
Git学习笔记 Git是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理. 在团队开发中git是必不可少的,它是目前为止最流行的版本控制工具 Git是免费.开源的,由Li ...
- (四)elasticsearch 源码之索引流程分析
1.概览 前面我们讨论了es是如何启动,本文研究下es是如何索引文档的. 下面是启动流程图,我们按照流程图的顺序依次描述. 其中主要类的关系如下: 2. 索引流程 我们用postman ...
- Nacos详解
Nacos是什么 欢迎来到Nocos的世界! 组成部分 全称 描述 Na naming/nameServer 即服务注册中心,与 Spring Cloud Eureka 的功能类似. co confi ...
- JavaFx 页面和控件设置快捷键
原文:JavaFx 页面和控件设置快捷键 - Stars-One的杂货小窝 之前说过一篇window系统全局快捷键的设置,本期主要是讲解JavaFx应用程序的快捷键设置,还是有所区别的 这里主要是To ...
- [C++Primer] 第二章 变量和基本类型
第二章 变量和基本类型 引用 引用定义的时候必须初始化. 引用初始化之后无法重新绑定到其它对象上. 引用本身并不是对象,所以没有指向引用的引用(不管如何多层引用,引用的还是源对象) 下面用一个简单的例 ...