Introduction to the

  • Used to read remote (GitHub or code cloud..) The configuration file

The sample

steps

  1. Create config-server and config-client
  2. Import dependence

The server reads the role of the remote configuration file, and the client reads the role of the configuration file from the server

  1. Write a configuration file and upload it to the remote device
  2. Create a simple configuration locally

  • Create Config – Server

Rely on

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
</dependency>
Copy the code

To start the class, use the @enableconFigServer annotation

@SpringBootApplication
@EnableConfigServer
public class ConfigServer_3344 {
    public static void main(String[] args) { SpringApplication.run(ConfigServer_3344.class,args); }}Copy the code

Application. Yaml configuration file

server:
  port: 3344

spring:
  application:
    name: springcloud-config-server-3344
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/kittyguy/springcloud-config.git

Copy the code

  • Create Eureka program (client for config-server)

Import dependence

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
    </dependencies>
Copy the code

Start the class

@SpringBootApplication
@EnableEurekaServer// Activate Eureka Server configuration comments
public class ConfigEureka_7001 {
    public static void main(String[] args) { SpringApplication.run(ConfigEureka_7001.class,args); }}Copy the code

Bootstrap. yaml configuration file

# system level
spring:
  cloud:
    config:
      uri: http://localhost:3344
      name: config-eureka  # Config file to use
      profile: dev
      label: master Which branch is in the warehouse
Copy the code

Remote warehouse

  • Tedious configuration in remote warehouse