springcloud config服务端配置(二)
生活随笔
收集整理的這篇文章主要介紹了
springcloud config服务端配置(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
接著上一篇把把本地倉庫yml文件推送到github之后,下面我們就是實戰了,各個微服務如何讀取到遠程倉庫的的yml文件配置
一,新建一個Module模塊microservicecloud-config-3344?它即為Cloud配置中心模塊
二,pom文件添加依賴
<?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>microservicecloud</artifactId><groupId>com.atguigu.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>microservicecloud-config-3344</artifactId><dependencies><!-- springCloud Config --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId></dependency><!-- 避免Config的Git插件報錯:org/eclipse/jgit/api/TransportConfigCallback --><!--<dependency><groupId>org.eclipse.jgit</groupId><artifactId>org.eclipse.jgit</artifactId><version>4.10.0.201712302008-r</version></dependency>--><!-- 圖形化監控 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><!-- 熔斷 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-hystrix</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-config</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jetty</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><!-- 熱部署插件 --><dependency><groupId>org.springframework</groupId><artifactId>springloaded</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId></dependency></dependencies></project>三,編寫啟動類,添加@EnableConfigServer注解?
package com.atguigu.springcloud;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer;@SpringBootApplication @EnableConfigServer public class Config_3344_StartSpringCloudApp {public static void main(String[] args) {SpringApplication.run(Config_3344_StartSpringCloudApp.class, args);} }四,編寫application.yml配置文件
server: port: 3344 spring:application:name: microservicecloud-configcloud:config:server:git:uri: git@github.com:470812087/microservicecloud-config.git #GitHub上面的git倉庫名字?uri: git@github.com:470812087/microservicecloud-config.git #GitHub上面的git倉庫名字從github上復制
?
?
啟動配置中心微服務?訪問:http://config-3344.com:3344/application-dev.yml
?
?
http://config-3344.com:3344/application-test.yml
訪問不存在的配置(不符合規則):
?
?訪問不存在的配置(符合規則):
?
?配置讀取規則
??
?
?
?
?
?
?
?
總結
以上是生活随笔為你收集整理的springcloud config服务端配置(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: S5PV210开发 -- 烧写/启动模式
- 下一篇: S5PV210开发 -- 通过 DNW、