【微服务】之三:从零开始,轻松搞定SpringCloud微服务-配置中心

官方解释

Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems (e.g. configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state). Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer's own laptop, bare metal data centres, and managed platforms such as Cloud Foundry.

本系列博文目录

【微服务】从零开始,轻松搞定SpringCloud微服务目录

说明:本系列源码持续更新,开始本篇之前先了解前面几篇文章。

开始起飞

基本思路:本文采用Git仓库作为配置文件的存放地址,通过创建一个配置中心服务器启动服务,然后再通过创建一个配置中心的客户端进行测试是否正常运转。

创建配置中心仓库

在原有的父类项目下创建一个普通的子项目,可以删除无关的文件,只留下空白项目。然后再创建一个测试的配置文件。

配置文件中加入测试数据

#随意设置的一个参数myblog:name:千万之路刚开始-author-hyhurl:http://www.hanyahong.comlocation:BeiJing

创建配置中心服务端

创建子项目

POM文件配置

在pom.xml文件中做一下配置

org.springframework.cloudspring-cloud-config-serverorg.springframework.bootspring-boot-starter-testtestorg.springframework.cloudspring-cloud-starter-eurekaorg.springframework.bootspring-boot-maven-plugin

配置项目resource配置文件

:整个博客是对各个子项目整合,因此加入了服务注册中心的相关配置

在resources文件夹下创建application.yml文件。并加入以下配置:

#服务端口

server:

port: 8082

#服务注册中心配置

eureka:

client:

serviceUrl:

defaultZone: http://localhost:8081/eureka/

#spring设置

spring:

application:

name: config-server

cloud:

config:

server:

git:

uri: https://github.com/hanyahong/spring-cloud-microservice.git

searchPaths: cloud-hyh-config-repo

创建主方法类

在创建完包以后,创建主方法。

@EnableDiscoveryClient@SpringBootApplication

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.1 数据库对比 缓存:将数据存储到内存中,只有当磁盘胜任不了的时候,才会启用缓存 缺点:断电数据丢失(双电),...
    创新科技宝典阅读 514评论 0 0
  • 创建数组 使用Array构造函数 使用数组字面量表示法 数组属性 length表示数组的长度 length属性并不...
    Dreammin_chen阅读 1,567评论 9 19
  • 27,我毕业6年,换了2个工作岗位,未婚,无子; 27,身体代谢越来越慢、皮肤越来越差,离酒吧越来越远、离小资越来...
    億无言阅读 220评论 0 0

友情链接更多精彩内容