依赖

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

注解

@EnableConfigServer
@EnableDiscoveryClient

bootstrap.yml

spring:
  application:
    name: config-center
  profiles:
    active: native # 如果是native,则为本地文件系统,如果为 git,则是git的仓库地址
  cloud:
    config:
      inetutils:
        preferred-networks:
          - ^192\.168.*
      server:
        native:
          searchLocations: classpath:/configs/{profile}
          # searchLocations: file:/d:/configs/{profile} # 硬盘目录的绝对路径
        git:
          uri: https://gitee.com/zhang.w/cloud-service-configs.git
          default-label: master
          force-pull: true
          searchPaths: "{profile}"
server:
  port: 0
eureka:
  client:
    serviceUrl:
      defaultZone: http://local.register.com:8761/eureka/
    registry-fetch-interval-seconds: 5
  instance:
    lease-expiration-duration-in-seconds: 15
    lease-renewal-interval-in-seconds: 5
    prefer-ip-address: true
    instance-id: ${spring.application.name}:${random.int} # 注册的服务名称

说明:

  1. {profile} - 指 config-client (使用同一配置管理的服务) 所使用的的 profile,而不是本项目的profile
  2. 本项目的 spring.profiles.active可以指定的有: natice/git/jdbc/svn,不能像普通的spring-cloud那样定义dev/test/prod等环境
  3. eureka.instance.instance-id 指的是服务注册时所使用的的服务名称,默认是${spring.application.name}.如果启动多个,用浏览器打开eureka中会重叠而会显示为一个,无法区分
  4. server.port=0 随机端口.为了本地高可用.