Spring cloud--鴻鵠Cloud分佈式微服務雲系統—Config

1.    介紹

Spring Cloud Config 爲分佈式系統中的外部配置提供服務器和客戶端支持。使用 Config Server,您能夠在全部環境中管理應用程序的外部屬性。客戶端和服務器上的概念映射與Spring Environment和PropertySource抽象相同,java

所以它們與 Spring 應用程序很是契合,但能夠與任何以任何語言運行的應用程序一塊兒使用。隨着應用程序經過從開發人員到測試和生產的部署流程,您能夠管理這些環境之間的配置,並肯定應用程序具備遷移時須要運行的一切。服務器存儲後端的默認實現使用 git,所以它輕鬆支持標籤版本的配置環境,以及能夠訪問用於管理內容的各類工具。很容易添加替代實現,並使用 Spring 配置將其插入。git

2.    引入 pom 相關 jar 包,其中 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.ml.honghu</groupId>
		<artifactId>commonservice</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>commonservice-config</artifactId>
	<packaging>jar</packaging>
	<name>commonservice-config</name>
	<description>Config Server</description>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-config-server</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>
		<dependency>
	<groupId>org.springframework.boot</groupId>
	
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>1</id>
						<goals>
							<goal>repackage</goal>
						</goals>
					</execution>
	<execution>
	<id>2</id>
	<goals><goal>build-info</goal>
	</goals>
	</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>

3.    在src/main/java進行ConfigApplication.java啓動文件配置:

package com.ml.honghu; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.config.server.EnableConfigServer; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 
@EnableConfigServer
@EnableEurekaClient
@SpringBootApplication public class ConfigApplication{  	public static void main(String[] args) { 
		SpringApplication.run(ConfigApplication.class, args); 
	}

4.    在 src/main/resource 下進行 bootstrap.yml 配置

server:  port: 8888 spring:   application: 
    name: commonservice-config-server 
  profiles: 
    active: discovery,native   cloud:     config:       server:         git: 
uri: http://192.168.0.254/honghu.../honghu-config.git           username: honghu           password: 123456           searchPaths: config-dev security:   basic: 
    enabled: true   user: 
    name: honghu     password: 123456 eureka:   client:     serviceUrl: 
defaultZone: http://honghu:123456@localhost:8761/eureka/       honghuZone: http://honghu:123456@localhost:8761/eureka/     registry-fetch-interval-seconds: 300     availability-zones: 
honghu: honghuZone   instance: 
    prefer-ip-address: true     metadataMap:       version: 1.0       variant: A       user: ${security.user.name}       password: ${security.user.password} management: 
  security: 
    enabled: false

注意: 若是不從遠程 git 或者 svn 庫加載配置文件信息,能夠配置加載本地地址,好比 window 下配置使用:spring

server:  port: 8888 spring:   application: 
    name: commonservice-config-server 
  profiles: 
    active: discovery,native   cloud:     config:       server: 
<span 	style="color: 	#ff0000;">native.searchLocations: d:/honghu-config</span>
security:   basic: 
    enabled: true   user: 
    name: honghu     password: 123456 eureka:   client:     serviceUrl: 
defaultZone: http://honghu:123456@localhost:8761/eureka/       honghuZone: http://honghu:123456@localhost:8761/eureka/     registry-fetch-interval-seconds: 300     availability-zones: 
honghu: honghuZone   instance: 
    prefer-ip-address: true     metadataMap:       version: 1.0       variant: A       user: ${security.user.name}       password: ${security.user.password} management: 
  security: 
enabled: false

到此,整個 config 服務項目配置完畢!!apache

從如今開始,我這邊會將近期研發的 spring cloud 微服務雲架構的搭建過程和精髓記錄下來,幫助更多有興趣研發 spring cloud 框架的朋友,你們來一塊兒探討 spring cloud 架構的搭建過程及如何運用於企業項目。企業分佈式微服務雲架構技術Spring Cloud+Spring Boot+Mybatis+shiro+RestFul+微服務源碼分享,技術支持1791743380bootstrap

相關文章
相關標籤/搜索