配置管理-SpringCloudConfig
1、搭建配置管理服务
添加依赖
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config-server</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>{$spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
配置application.yml文件
server:
port: 8004
spring:
application:
name: configServer
cloud:
config:
server:
git:
uri: 您的git仓库地址
searchPaths: /**
defaultLabel: master
#若是私有需填入帐号密码
#username:
#password:
[注]:仓库下的配置文件为application-dev.yml
启动服务,浏览器中查看如下
2.注册服务客户端配置
添加依赖
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>{$spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
配置bootstrap.yml文件
spring:
application:
name: oauth2
cloud:
config:
uri: http://localhost:8004/
label: master
profile: dev