Summary of the config

The configuration center provides a centralized external configuration. By default, Git is used to store configuration information, so that configuration information can be version managed. The configuration center below is based on Git. The configuration center runs as a separate service.

Spring Cloud allows runtimeDynamic refresh configurationNew configuration information can be retrieved from the configuration center.

Yml Bootstrap. yml Bootstrap. yml Bootstrap. yml Bootstrap. yml Bootstrap. yml Bootstrap. yml

The config implementation

Step 1: Create a new Java project config

Use as a folder to store configuration files.

Assign sp02, 03, 04, 11 to config and rename the spring profile.

#item-service-dev.yml - #item-service-dev.yml - Development starts at development time, master + development merge, and starts simultaneously. #item-service-test.yml - Test #item-service-dev.prod - Production #item-service-xxx.yml -



Step 3: Add configuration to the four configuration files in the config and annotate the configuration files of sp02, sp03, sp04 and sp11

Cloud :config:override-none: true Cloud :config:override-none: true Cloud :config:override-none: true

Create configuration files item-service-dev.yml separately:

# item-service ----->localhost: spring: application: name: # item-service ----->localhost: spring: application: name: Cloud: config: override: none: true server: port: 8001 eureka: client: service-url: defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka

Comment SP02, SP03, SP04, SP11 configuration files:

## application.yml ## ## Give the application a name and register it with the registry: ## Registration information: item-service ----->localhost: #spring: # application: # name: item-service # #server: # port: 8001 # #eureka: # client: # service-url: # defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka

Step 4: Create a local repository



Select the local repository directory and files



Step 5: Push the local repository commit to the Gitee remote repository

1. Click on the commit



2. Check the documents to be submitted, fill in the submission information, and submit



Click Commit to commit the file to the local repository



3. Create repository SpringCloud1 on Gitee





Replicate warehouse address



4. Click Push to start pushing from the local warehouse to the remote warehouse.



Fill in the link and click OK



Push push



Check to see if the push was successful



Step 6: Create SpringBoot project sp12-config



Step 7: Add config server, eureka dependencies

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

Step 8: Configure the POM file

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/duchaosa/springcloud1
          searchPaths: config
          #username: your-username
 #password: your-password
server:
  port: 6001
eureka:
  client:
    service-url:
      defaultZone: http://eureka1:2001/eureka, http://eureka2:2002/eureka

Step 9: Add annotations @EnableConfigServer and @EnableDiscoveryClient to the main program

package cn.tedu.sp12; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.config.server.EnableConfigServer; @EnableConfigServer @EnableDiscoveryClient @SpringBootApplication public class Sp12ComfigApplication { public static void main(String[] args) { SpringApplication.run(Sp12ComfigApplication.class, args); }}

Step 10: Start server SP12 and access the tests

http://localhost:6001/item-service-dev.yml

http://localhost:6001/item-service/dev



Step 11: Configure the central client

1. POM of SP02, SP03, SP04 and SP11 projects

Add the config dependency in the file respectively

<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

2. Create bootstrap.yml files in SP02, SP03, SP04 and SP11 projects respectively and pull the config server from Eureka registry and get the client configuration file. Boot the configuration file before application.yml is loaded.

Item – service:

Eureka: client: service-url: defaultZone: eureka: client: service-url: defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka spring: cloud: config: discovery: enabled: true service-id: # item-service-dev.yml Name: item-service profile: dev

User – service:

Eureka: client: service-url: defaultZone: eureka: client: service-url: defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka spring: cloud: config: discovery: enabled: true service-id: # user-service-dev.yml name: user-service profile: dev

The order – service:

Eureka: client: service-url: defaultZone: eureka: client: service-url: defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka spring: cloud: config: discovery: enabled: true service-id: Yml name: order-service profile: dev

Zuul – service:

Eureka: client: service-url: defaultZone: eureka: client: service-url: defaultZone: http://eureka1:2001/eureka,http://eureka2:2002/eureka spring: cloud: config: discovery: enabled: true service-id: # zuul-dev.yml name: zuul profile: dev

3. Start the server to see if the server has successfully pulled up the configuration file.