1.Spring Cloud Config 分布式配置

  a.Config服务器

    ①新建springboot项目,依赖选择Config Server

    ②pom文件关键依赖

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency> ...... </dependencies> ......

    ③application.yml文件

spring:
application:
name: config-server
profiles:
#配置文件在本地
active: native
#配置文件的目录
cloud:
config:
server:
native:
search-locations: classpath:/config server:
port: 8101

    ④启动类添加注解@EnableConfigServer

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication { public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
} }

    ⑤在resources下新建config/commom-dev.properties,用于测试

test.name=vettel
test.password=111111

    ⑥启动后访问 http://localhost:8101/common/dev 可查看配置文件信息,访问路径有如下几种

      /{application}/{profile}[/{label}]

      /{application}-{profile}.yml

      /{label}/{application}-{profile}.yml

      /{application}-{profile}.properties

      /{label}/{application}-{profile}.properties

      注:对于resources下的config/commom-dev.properties,{application}为文件名"commom",{profile}为环境名"dev",{label}为路径名"config"。

  b.Config客户端

    ①新建springboot项目,依赖选择 Config Client 、Web

    ②pom文件关键依赖

    <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency> ...... </dependencies> ......

    ③bootstrap.yml文件

spring:
application:
name: config-client
cloud:
config:
uri: http://localhost:8101
profile: dev
name: common server:
port: 8102

    注意:此处需要将配置写入bootstrap.yml(会优先于application.yml加载)中,因为config的配置是优先于application.yml加载的,否则会报错。

    ④具体使用

@SpringBootApplication
@RestController
public class ConfigClientApplication { public static void main(String[] args) {
SpringApplication.run(ConfigClientApplication.class, args);
} @Value("${test.name}")
String name;
@Value("${test.password}")
String password; @RequestMapping(value="/getConfig")
public String getConfig(){
return "name[" + name + "], password[" + password + "]";
} }

微服务框架——SpringCloud(四)的更多相关文章

  1. 微服务框架——SpringCloud

    1.SpringCloud微服务框架 a.概念:SpringCloud是基于SpringBoot的微服务框架 b.五大神兽:Eureka(服务发现).Ribbon(客服端负载均衡).Hystrix(断 ...

  2. 微服务框架SpringCloud(Dalston版)学习 (一):Eureka服务注册与发现

    eureka-server eureka服务端,提供服务的注册与发现,类似于zookeeper 新建spring-boot工程,pom依赖: <dependency> <groupI ...

  3. 微服务框架SpringCloud与Dubbo

    #v1.0.0# 1.背景 Dubbo,是阿里巴巴服务化治理的核心框架,并被广泛应用于阿里巴巴集团的各成员站点.阿里巴巴近几年对开源社区的贡献不论在国内还是国外都是引人注目的,比如:JStorm捐赠给 ...

  4. 微服务框架——SpringCloud(三)

    1.Zuul服务网关 作用:路由转发和过滤,将请求转发到微服务或拦截请求.Zuul默认集成了负载均衡功能. 2.Zuul实现路由 a.新建springboot项目,依赖选择 Eureka Discov ...

  5. 微服务框架——SpringCloud(二)

    1.Feign声明式服务调用(负载均衡+熔断器) a.概念:Feign是一个声明式的Web Service客户端,它的目的就是让Web Service调用更加简单.Feign整合了Ribbon和Hys ...

  6. .NET Core Community 第四个千星项目诞生:微服务框架 Surging

    本文所有打赏将全数捐赠于 NCC(NCC 的资金目前由 倾竹大人 负责管理),请注明捐赠于 NCC.捐赠情况将由倾竹大人在此处公示. 提及 .NET 微服务,我们脑海中浮现的一系列印象中,总有 Sur ...

  7. java框架之SpringCloud(1)-微服务及SpringCloud介绍

    微服务概述 是什么 业界大牛 Martin Fowler 这样描述微服务: 参考[微服务(Microservices)-微服务原作者Martin Flower博客翻译]. 下面是关于上述博客中的部分重 ...

  8. 基于Spring-Cloud的微服务框架设计

    基于Spring-Cloud的微服务框架设计 先进行大的整体的框架整理,然后在针对每一项进行具体的详细介绍

  9. 微服务框架Dubbo与Springcloud的区别

    微服务框架Dubbo与Springcloud的区别 微服务主要的优势如下: 1.降低复杂度 将原来偶合在一起的复杂业务拆分为单个服务,规避了原本复杂度无止境的积累.每一个微服务专注于单一功能,并通过定 ...

随机推荐

  1. LinkedBlockingQueue阻塞队列详解

    主要api java.util.concurrent包下的新类.LinkedBlockingQueue就是其中之一,是一个阻塞的线程安全的队列,底层采用链表实现.        LinkedBlock ...

  2. 深入理解Java自带的线程池和缓冲队列

    前言 线程池是什么 线程池的概念是初始化线程池时在池中创建空闲的线程,一但有工作任务,可直接使用线程池中的线程进行执行工作任务,任务执行完成后又返回线程池中成为空闲线程.使用线程池可以减少线程的创建和 ...

  3. luasocket编译安装遇到的坑

    由于需要获得本机的IP地址,所以需要 : local socket = require('socket') local server_hostname = socket.dns.gethostname ...

  4. addEventListener解决多个window.onscroll共存的2个方法

    方法1.(注意第一个和第二个的先后次序) window.onscroll=function(){console.log('第一个');} var oldMethod = window.onscroll ...

  5. linux常用系统指令

    [linux常用系统指令] 查看内核版本:cat /proc/version 查看发行版本:cat /etc/issue 通过安装lsb的方式查看发行版本: yum provides */lsb_re ...

  6. P2P互联网金融企业的四大转型方向

    1.按照国标做成百分百的信息中介平台.这个定位太低,无利可图,如果政策导向真按着这个路径走,未来可能只剩下不到50家平台; 2.转型成为带“民营银行”属性的平台.这还得国家网开一面,学习英国模式,允许 ...

  7. Django unittest 单元测试

    这里就不再介绍单元测试的作用了. 首先单元测试的创建方式有两种,一种是app下面的test文件,另一种是自定义方式创建 方法一.使用test.py文件测试 from django.test impor ...

  8. Corn Fields POJ - 3254 (状压dp)

    题目链接: Corn Fields  POJ - 3254 题目大意:给你一个n*m的矩阵,矩阵的元素只包括0和1,0代表当前的位置不能放置人,1代表当前的位置可以放人,当你决定放人的时候,这个人的四 ...

  9. Windows如何上传代码到Github

    1.首先得安装git客户端 进入官网:https://git-scm.com/ ,点击右侧下载windows版本的软件包,然后双击安装就可以了. 安装完成之后,在开始菜单可以看到,此时,在想上传的文件 ...

  10. windows安装pycrypto报错

    在Windows上安装的时候直接 pip install pycrypto会报错 由于直接安装安装Crypto模块 会报错如下:因此需要先安装Microsoft Visual C++ 9.0 进入下载 ...