In a distributed system, due to the huge number of multi-service, service profile in order to facilitate unified management, real-time updates, so they need the central component of a distributed configuration. In Spring Cloud, there is a central component of a distributed configuration Spring Cloud Config, which supports the configuration service in memory configuration services (ie local), also supported on the remote Git repository. In Spring Cloud Config components, the two roles, one Config Server, and second, Config Client.
This center is a distributed configuration management system files
Work premise: the existence eureka server
1. Build projects itoken-config
File Directory:
2.pom.xml
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.pengt</groupId> <artifactId>itoken-dependencies</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../itoken-dependencies/pom.xml</relativePath> </parent> <artifactId>itoken-config</artifactId> <packaging>jar</packaging> <name>itoken-config</name> <dependencies> <!-- Spring Boot Begin --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- Spring Boot End --> <!-- Spring Cloud Begin --> <!--分布式配置中心--> <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-server</artifactId> </dependency> <!-- Spring Cloud End --> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <mainClass>com.pengt.itoken.config.ItokenConfigApplication</mainClass> </configuration> </plugin> </plugins> </build> </project>
application.yml
Spring: file application: name: IToken-config Cloud: config: label: Master Master // branch Server: Git: URI: https://github.com/13671664132/center-config Search-Paths: Respo username: // of GitHub username password: // password Server: Port: 8888 Eureka: Client: serviceUrl: defaultzone: HTTP: // localhost: 8761 / Eureka /
ItokenConfigApplication
@SpringBootApplication @EnableEurekaClient @EnableConfigServer public class ItokenConfigApplication { public static void main(String[] args) { SpringApplication.run(ItokenConfigApplication.class,args); } }
3. testing services, require access to the service through the configuration file on git
1. Upload properties file itoken-zuul.yml path at https://github.com/13671664132/center-config/respo
2. Start eureka server, start the config service
3.访问 http://localhost:8888/itoken-zuul/master
Properties file can be read out on the branch github through config service, indicating that the server distributed configuration center has been set up successfully,
After the file attributes related services can be maintained directly on git, do unified management.