SpringCloud------配置中心Config

1.

 什么是配置中心

  统一管理配置,怏速切换各个环境的配置


相关产品:
百度的 discont
  https://github.com/knightliao/disconf
阿里的diamand
  https://github.com/takeseem/diamond
springcloud的configs-server:
  http://cloud.spring.io/spring-cloud-config/

推荐文章

  http://jm.taobao.org/2016/09/28/an-article-about-config-center/

2.添加依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

3.启动类添加注解@EnableConfigServer

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

@SpringBootApplication
@EnableConfigServer
public class ConfigServiceApplication {

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

}
扫描二维码关注公众号,回复: 9876958 查看本文章

4.修改application.yml配置

server:
  port: 9100
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          #仓库地址,去掉git
          uri: https://gitee.com/YTHeng/config_cloud
          #git服务器登录的用户名和密码,我这边使用的是码云
          username: [email protected]
          password: 12345678.
          #超时时间
          timeout: 5
          #分支
          default-label: master

5.在码云服务器新建仓库和文件

6.访问地址

http://localhost:9100/master/product-service-dev.yml

路径访问方式

/{name}-{profiles}. properties
/{name}-{profiles}.yml
/{name}-{profiles}.json
/{label}/{name]-{profiles].yml


name:服务器名称
profile:环境名称,开发、测试、生产
Lable:仓库分支、默认 master分支

另附:

猜你喜欢

转载自www.cnblogs.com/tianhengblogs/p/12507862.html