SpringCould总结 | 第七篇 分布式服务配置中心ConfigServer

//1.工程结构


//2.pom结构

<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>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.8.RELEASE</version>
		<relativePath />
	</parent>

  <groupId>com.spc.config.server</groupId>
  <artifactId>spc-config-server</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>spc-config-server</name>
  <url>http://maven.apache.org</url>

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

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

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

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

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>

//3.配置文件

spring.application.name=spc-config-server
server.port=5000

spring.cloud.config.server.git.uri=https://github.com/zhangsan001github/spc-config-repositry.git
spring.cloud.config.server.git.searchPaths=respo
spring.cloud.config.label=master
spring.cloud.config.server.git.username=your username
spring.cloud.config.server.git.password=your password

//4.服务类

package com.spc.config.server.spc_config_server;

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;

@SpringBootApplication
@EnableConfigServer
@EnableDiscoveryClient
public class ConfigServerApplication {

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

//运行结果


//可以看到 通过访问配置中心 可以取到git仓库的文件 git地址为公开类型均可使用

#配置git仓库的地址

spring.cloud.config.server.git.uri=https://github.com/zhangsan001github/spc-config-repositry.git

#配置路径可以按工程名来分可以吧respo改成工程名 按不同的工程归纳配置文件

spring.cloud.config.server.git.searchPaths=respo

#该git仓库的分支

spring.cloud.config.label=master

#git仓库的用户名 git仓库为public类型时 用户名和密码可以不填

spring.cloud.config.server.git.username=your username

#git仓库的密码

spring.cloud.config.server.git.password=your password
posted @ 2018-06-27 22:16  蜜獾互联网  阅读(1)  评论(0编辑  收藏  举报  来源