版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hcmony/article/details/82777974
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上面创建仓库,或者用我的
springcloud 源代码 https://github.com/hcmony/springcloud.git
idea创建maven,spring,springmvc,mybatis,项目(二)
idea创建maven,spring,springmvc,mybatis,项目(三)
idea创建springboot项目图文教程(配置文件)(五)
idea创建springcloud项目图文教程(EurekaServer注册中心)(六)
idea创建springcloud项目图文教程(创建服务提供者)(七)
idea创建springcloud项目图文教程(创建消费者)(八)
idea创建springcloud项目图文教程(Feign实现负载均衡)(九)