官方解釋
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.
本系列博文目錄
【微服務(wù)】從零開(kāi)始荠割,輕松搞定SpringCloud微服務(wù)目錄
說(shuō)明:本系列源碼持續(xù)更新吟宦,開(kāi)始本篇之前先了解前面幾篇文章疫衩。
開(kāi)始起飛
基本思路:本文采用Git倉(cāng)庫(kù)作為配置文件的存放地址钮呀,通過(guò)創(chuàng)建一個(gè)配置中心服務(wù)器啟動(dòng)服務(wù)扛邑,然后再通過(guò)創(chuàng)建一個(gè)配置中心的客戶端進(jìn)行測(cè)試是否正常運(yùn)轉(zhuǎn)怜浅。
創(chuàng)建配置中心倉(cāng)庫(kù)
在原有的父類項(xiàng)目下創(chuàng)建一個(gè)普通的子項(xiàng)目,可以刪除無(wú)關(guān)的文件蔬崩,只留下空白項(xiàng)目恶座。然后再創(chuàng)建一個(gè)測(cè)試的配置文件。
配置文件中加入測(cè)試數(shù)據(jù)
#隨意設(shè)置的一個(gè)參數(shù)myblog:name:千萬(wàn)之路剛開(kāi)始-author-hyhurl:http://www.hanyahong.comlocation:BeiJing
創(chuàng)建配置中心服務(wù)端
創(chuàng)建子項(xiàng)目
POM文件配置
在pom.xml文件中做一下配置
org.springframework.cloudspring-cloud-config-serverorg.springframework.bootspring-boot-starter-testtestorg.springframework.cloudspring-cloud-starter-eurekaorg.springframework.bootspring-boot-maven-plugin
配置項(xiàng)目resource配置文件
注:整個(gè)博客是對(duì)各個(gè)子項(xiàng)目整合沥阳,因此加入了服務(wù)注冊(cè)中心的相關(guān)配置
在resources文件夾下創(chuàng)建application.yml文件跨琳。并加入以下配置:
#服務(wù)端口
server:
port: 8082
#服務(wù)注冊(cè)中心配置
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8081/eureka/
#spring設(shè)置
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/hanyahong/spring-cloud-microservice.git
searchPaths: cloud-hyh-config-repo
創(chuàng)建主方法類
在創(chuàng)建完包以后,創(chuàng)建主方法桐罕。
@EnableDiscoveryClient@SpringBootApplication