七: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. 随笔——mvc公众号自动登录跳转到原页面的方法

    页面路径传参跳到那带到哪 1.全局过滤(继承过滤也行).这里使用的全局过滤 2.过滤判断需要登录的话,获取本次路径传到登录的页面 3.登录的页面判断是微信浏览器的话,参数带到微信登录接口 4.微信登录 ...

  2. jmeter中下一接口依赖上一接口的参数,上一个接口存在分页时,如何在下一接口循环读取上一接口的数据?

    问题背景: 工作中性能测试存在接口数据依赖,B接口依赖A接口的数据,希望提取到A接口的数据,传入到B接口,但是A接口存在分页的情况. 如何保证A接口返回的数据未知,且每次从A接口传给B接口的数据不重复 ...

  3. QT+VS 调用基于Google Breakpad的跨平台Qt崩溃异常捕获调用方案

    方案一.基于Google Breakpad的跨平台Qt崩溃异常捕获调用方案 首先上博客:Windows下Qt生成dump文件并定位bug(基于qBreakpad) 这个地方使用的是一个叫qBreakP ...

  4. java中的复合赋值运算符

    本文主要阐明复合赋值运算符 即 i = i+ 1.2 ==> i += 1.2: int i = 1; i += 1.2; System.out.println(i); // i == 2 注意 ...

  5. Jmeter之非GUI下执行脚本

    1.进入jmeter 应用所在路径 eg: cd D:\Program Files\apache-jmeter-5.2\bin 2.输入运行命令:jmeter -n -t [jmx脚本路径] -l [ ...

  6. [OpenCV实战]47 基于OpenCV实现视觉显著性检测

    人类具有一种视觉注意机制,即当面对一个场景时,会选择性地忽略不感兴趣的区域,聚焦于感兴趣的区域.这些感兴趣的区域称为显著性区域.视觉显著性检测(Visual Saliency Detection,VS ...

  7. Pytorch基础-张量基本操作

    一,张量的基本操作 二,维度变换 2.1,squeeze vs unsqueeze 维度增减 2.2,transpose vs permute 维度交换 三,索引切片 3.1,规则索引切片方式 3.2 ...

  8. linux系统一键开启root登陆

    服务器只能key登陆,用这个后直接可以root方式登陆 sudo -i echo root:要设置的密码 |sudo chpasswd root sudo sed -i 's/^#\?PermitRo ...

  9. 避免用Apache Beanutils进行属性的copy。why?让我们一起一探究竟

    在实际的项目开发中,对象间赋值普遍存在,随着双十一.秒杀等电商过程愈加复杂,数据量也在不断攀升,效率问题,浮出水面. 问:如果是你来写对象间赋值的代码,你会怎么做? 答:想都不用想,直接代码走起来,g ...

  10. pip19.2.3升级到20.3.3版本升级失败问题

    2021-01-06 macOS版本:11.1 安装pip: sudo easy_install pip   话不多说,直接上问题   一行命令搞定 终端:sudo pip install --upg ...