七: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 本地配置的更多相关文章

  1. Spring Cloud Config(配置中心)

    每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 一.简介 Spring Cloud Config为分布式系统中的外部配置提供服务器和客 ...

  2. spring cloud config将配置存储在数据库中

    Spring Cloud Config Server最常见是将配置文件放在本地或者远程Git仓库,放在本地是将将所有的配置文件统一写在Config Server工程目录下,如果需要修改配置,需要重启c ...

  3. 跟我学SpringCloud | 第六篇:Spring Cloud Config Github配置中心

    SpringCloud系列教程 | 第六篇:Spring Cloud Config Github配置中心 Springboot: 2.1.6.RELEASE SpringCloud: Greenwic ...

  4. Spring Cloud Config 实现配置中心,看这一篇就够了

    Spring Cloud Config 是 Spring Cloud 家族中最早的配置中心,虽然后来又发布了 Consul 可以代替配置中心功能,但是 Config 依然适用于 Spring Clou ...

  5. Spring Cloud Config的配置中心获取不到最新配置信息的问题

    Spring Cloud Config的配置中心获取不到最新配置信息的问题 http://blog.didispace.com/spring-cloud-tips-config-tmp-clear/

  6. Spring Cloud Config 分布式配置中心使用教程

    一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...

  7. Spring Cloud Config 分布式配置中心【Finchley 版】

    一. 介绍 1,为什么需要配置中心? 当服务部署的越来越多,规模越来越大,对应的机器数量也越来越庞大,靠人工来管理和维护服务的配置信息,变得困难,容易出错. 因此,需要一个能够动态注册和获取服务信息的 ...

  8. 为Spring Cloud Config Server配置远程git仓库

    简介 虽然在开发过程,在本地创建git仓库操作起来非常方便,但是在实际项目应用中,多个项目组需要通过一个中心服务器来共享配置,所以Spring Cloud配置中心支持远程git仓库,以使分散的项目组更 ...

  9. 重写spring cloud config 本地bootstrap

    在spring-cloud中使用了config-server之后,需要在client端加入bootstrap作为配置文件,其中通常包含如下: spring.application.name=ms-as ...

  10. Spring Cloud Config的配置中心使用非对称性加密

    首先,我们需要通过keytool工具来生成密钥对. keytool是JDK中的一个密钥和证书管理工具.它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认 ...

随机推荐

  1. VM安装Centos7操作系统

    个人名片: 对人间的热爱与歌颂,可抵岁月冗长 Github‍:念舒_C.ying CSDN主页️:念舒_C.ying 个人博客 :念舒_C.ying 视频教程:https://live.csdn.ne ...

  2. Spring Boot中@Import三种使用方式!

    需要注意的是:ImportSelector.ImportBeanDefinitionRegistrar这两个接口都必须依赖于@Import一起使用,而@Import可以单独使用. @Import是一个 ...

  3. 关于解决windows安装gcc g++环境 mingw失败

    前言 这几天学习c++,为了详细了解编译过程我没有安装vs全家桶,当然使用命令行是最好的方法. 但是为了解决这个网络问题折腾了我很久,经过我研究发现,其实就是到固定网站下载几个压缩格式的文件,然后解压 ...

  4. 基于opencv实现简单人脸检测

    作用:在视频中自动检测出人脸 使用内容:灰度转换,分类器,矩形框选,圆形框选,摄像头读取及释放 代码逻辑: 先读取摄像头后, 对摄像头拍摄到的图片进行逐帧分析, 并对图像进行灰度转换后使用类选择器识别 ...

  5. view-design table的renderHeader中hover添加checkboxGroup遇到的问题

    示例demo https://codepen.io/sphjy/pen/mdKaQJZ 问题见图 勾选多个复选框 on-change事件返回的数据只有当前点击的这一项,而且设置在checkboxGro ...

  6. python解释器下载与基本使用

    python介绍与解释器下载基本使用 1.python发展方向 ​ web方向.自动化运维.自动化测试.自动化办公.网络爬虫.金融量化.人工智能.机器学习.数据分析 2.python解释器 ​ 历史 ...

  7. Jmeter在结果树中查看响应数据为空

    今天遇到了一个比较尴尬的问题,吭哧吭哧了大半天,后来咨询了开发SO的一下解决了. 问题: 在调用接口时取样器结果中显示response code:200, response message:OK,但是 ...

  8. kali安装拼音输入法

    前言 最近使用kali感觉没个中文输入法的很不方便,于是决定装个ibus的拼音输入法 安装方法 1.安装ibus 使用命令apt install ibus ibus-pinyin,注意使用root权限 ...

  9. WireShark抓包入门教学

    wireshark抓包新手使用教程 Wireshark是非常流行的网络封包分析软件,可以截取各种网络数据包,并显示数据包详细信息.常用于开发测试过程各种问题定位.本文主要内容包括: 1.Wiresha ...

  10. [编程基础] Python对象的浅拷贝与深拷贝笔记

    Python中的赋值语句不创建对象的副本,它们只将名称绑定到对象.对于不可变的对象,这通常没有什么区别.但是对于处理可变对象或可变对象的集合,您可能需要寻找一种方法来创建这些对象的"真实副本 ...