pom.xml
1 2 3 4
| <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
|
application.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| server: port: 7006
spring: application: name: config-server cloud: config: server: git:
uri: https://github.com/Delena1988/spring-cloud-config-repo
search-paths: /**
username:
password:
label: master
|
ConfigServerApplication.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| package com.linjian.configserver;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer;
@EnableConfigServer @SpringBootApplication public class ConfigServerApplication {
public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }
}
|
Github创建repository spring-cloud-config-repo
创建配置文件
spring-cloud-config-dev.yml
spring-cloud-config-test.yml
spring-cloud-config-pro.yml
测试:
启动Config-server
访问 http://localhost:7006/master/spring-cloud-config-dev.yml
访问 http://localhost:7006/master/spring-cloud-config-test.yml
访问 http://localhost:7006/master/spring-cloud-config-pro.yml