spring cloud config service 使用

spring cloud config service use


1. Register an account on gitHud
2. Create a test directory
3. Create a configClient-test.properties file, the file has rules, configClient indicates the service name using this configuration file, -test indicates that it is used for testing The
content :
foo=fooTest



<?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>


	<groupId>com.midea</groupId>
	<artifactId>base</artifactId>
	<version>1.0-SNAPSHOT</version>
	<packaging>jar</packaging>
	<name>base</name>


	<!-- Set the warehouse, search according to the set order. -->
	<!--<repositories> <repository> <id>public</id> <name>Team Nexus Repository</name>
		<url>http://10.33.183.113:8081/nexus/content/groups/public</url> <snapshots>
		<enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots>
		</repository> </repositories> <pluginRepositories> <pluginRepository> <id>public</id>
		<name>Team Nexus Repository</name> <url>http://10.33.183.113:8081/nexus/content/groups/public</url>
		<snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots>
		</pluginRepository> </pluginRepositories> -->

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.2.RELEASE</version>
	</parent>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Dalston.SR1</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

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

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

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

		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger2</artifactId>
			<version>2.4.0</version>
			<exclusions>
				<exclusion>
					<groupId>org.slf4j</groupId>
					<artifactId>slf4j-api</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>io.springfox</groupId>
			<artifactId>springfox-swagger-ui</artifactId>
			<version>2.4.0</version>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-log4j2</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
			<exclusions>
				<exclusion>
					<groupId>org.springframework.boot</groupId>
					<artifactId>spring-boot-starter-logging</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
	</dependencies>
	<build>

	</build>
</project>





server.port=8888


#server path
#server.context-path=/eurekaServer

spring.application.name=config-server

#gitHub path
spring.cloud.config.server.git.uri=https://github.com/huangyongxing310/springCloudConfigTest.git
#File path, if it is the root directory, it can not be configured
spring.cloud.config.server.git.searchPaths=test
#Configure the branch of the repository,
spring.cloud.config.label=master
#gitHub account password
[email protected]
spring.cloud.config.server.git.password=xing310600



package com;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;



@SpringBootApplication //spring boot starts the application
@EnableConfigServer //Indicates that the Config service is enabled
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

}




After startup:

http://localhost:8888/configClient/test/master

http://localhost:8888/configClient/test

all get the same result






http request address and resource file mapping as follows:
/{application}/{profile}[ /{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile }.properties














Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326561185&siteId=291194637