1. 程式人生 > >idea建立springcloud專案圖文教程(config 實現配置中心)(十一)

idea建立springcloud專案圖文教程(config 實現配置中心)(十一)

1,先建立config-server 專案配置如下

package com.hcmony;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;


@EnableEurekaServer
@SpringBootApplication
public class ConfigApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConfigApplication.class, args);
	}
}
eureka.client.service-url.defaultZone= http://localhost:8888/eureka/
#config-server對外提供的埠
server.port=8200

spring.application.name=config-server
#git repo的url地址
spring.cloud.config.server.git.uri=https://github.com/hcmony/config.git
spring.cloud.config.server.git.search-paths=/dev
spring.cloud.config.label=master

#spring.cloud.config.server.git.username=
#spring.cloud.config.server.git.password=


<?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.hcmony</groupId>
		<artifactId>springcloud-hotchpotch</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>config-server</artifactId>
	<build>

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

2,建立config-client 專案配置如下

<?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.hcmony</groupId>
		<artifactId>springcloud-hotchpotch</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	<artifactId>config-client</artifactId>
	<build>

	</build>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-config</artifactId>
		</dependency>
	</dependencies>
</project>
package com.hcmony;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;


@SpringBootApplication
public class ConfigClientApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConfigClientApplication.class, args);
	}
}
spring.application.name=config-client
eureka.client.service-url.defaultZone= http://localhost:8888/eureka/


#配置中心{application},例如檔名為 neo-config-dev.properties ; spring.cloud.config.name=neo-config ; spring.cloud.config.profile=dev
spring.cloud.config.name=config-client
#對應配置中心的{profile}
spring.cloud.config.profile=dev
#指定從master分支讀取配置檔案
spring.cloud.config.label=master
#配置中心服務地址
spring.cloud.config.uri=http://localhost:8200
#開啟配置服務發現
spring.cloud.config.discovery.enabled=true
#配置服務例項名稱
spring.cloud.config.discovery.service-id=config-server
spring.cloud.config.fail-fast=true
spring.cloud.config.enabled=true

3,在github上面建立倉庫,或者用我的