Config Server负责跟配置保存方通信例如git,将远程服务器上的配置克隆到本地。
springcloudconfig\shared目录下建立
server:
port: 9900
foo: dev foo version
server:
port: 9900
foo: test foo version
新建release1.0分支
增加label参数,下为开发,测试一致
server:
port: 9900
foo: dev foo version
label: release1.0
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
server:
port: 9800
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/wenrongyao/springcloudconfig/
search-paths: shared
username: # 公共仓库可以不写
password: # 公共仓库可以不写
@SpringBootApplication
@EnableConfigServer
public class ConfigServer9800Application {
public static void main(String[] args) {
SpringApplication.run(ConfigServer9800Application.class, args);
}
}
用我们前面建立的两个配置文件来做说明:
config-client指的是{application}部分
dev/test指的是{profile部分}
{label}值得是git的版本号
eg:下面两者都可以访问配置文件,当label不写时默认为master
http://localhost:9800/config-client/dev/release1.0
http://localhost:9800/release1.0/config-client-dev.yml