I. Directory structure
Two, pom file
<!--Configuration service dependent- <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <!--Eureka Client Dependent- <dependency> <groupId>org.springframework.cloud</groupId> < Artifactid>spring-cloud-starter-eureka</artifactid> </dependency>
<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 >
Spring-cloud-dependencies move to Pom file in Microservice
Third, the configuration of Yml 1.bootstrap.yml
Spring: profiles: native #配置服务器使用本地配置, default git configuration application: Name:micro -service-Config # service name registered in Eureka Eureka: instance: non-secure-port: ${server.port:8763 The value in environment variable is used in the environment variable , if not, the default 8080 port metadata-map: instanceId: ${ Spring.application.name}:${random.value} #配置在Eureka Server ID client: service-URL: Defaultzone:http://localhost1:8761/eureka/,http://localhost2: 8762/ eureka/ #注册到Eureka Server
2.application.yml
Spring: Cloud: config: server: native: search-locations: classpath:/config #配置文件所在位置server: 8763
Iv. Start Microservice-config
PackageCom.nc.cloud.microservice.config;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;ImportOrg.springframework.cloud.config.server.EnableConfigServer;Importorg.springframework.cloud.netflix.eureka.EnableEurekaClient, @SpringBootApplication @enableconfigserver//turn on configuration server support@EnableEurekaClient//Turn on Eureka client Support Public classconfigapplication { Public Static voidMain (string[] args) {Springapplication.run (configapplication.class, args); }}
Spring Boot Starter (iv) Config Server Unified Configuration Center for MicroServices