首先須要創建一個server端:git
pom依賴中加入spring
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
因爲這裏只是拉取配置,並不須要幹其餘事情,因此只須要加入上面那個依賴就能夠,不須要額外加入其餘東西bootstrap
server: port: 8080 spring: application: name: microservice-config-server cloud: config: server: git: uri: https: # 配置Git倉庫的地址 username: # Git倉庫的帳號 password:
啓動類:app
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; @SpringBootApplication @EnableConfigServer public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } }
服務端:spa
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
因爲這是一個項目,須要向外提供服務,因此須要加入其餘東西,本來相應的依賴都須要加入code
須要創建一個application。ymlserver
server: port: 8081
還有一個bootstrap。ymlblog
spring: application: name: microservice-foo # 對應config server所獲取的配置文件的{application} cloud: config: uri: http://localhost:8080/ profile: dev # profile對應config server所獲取的配置文件中的{profile} label: master
這樣就能夠引用了it