Spring Cloud Config 为分布式系统中的外部配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器上的概念映射与Spring Environment和PropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。可以轻松添加替代实现,并使用Spring配置将其插入。
Spring Cloud(三)配置服务 Config
Spring Cloud(三)配置服务 Config
注意:当我们建立配置服务的时候,同时也需要安装 eureka disconvery,这样才能把配置服务注册到注册中心。

@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class ConfigApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}
#服务端口
server:
  port: 9091

#应用名称
spring:
  application:
    name: config
  #配置加载环境:native、subversion、git
  profiles:
    active: native
  cloud:
    config:
      server:
        svn:
          uri:svn://gitee.com/vincent_git/config
          username:vincent_git
          password:Xx13676223989
        bootstrap: true
#eureka客服端
eureka:
  instance:
    hostname: 127.0.0.1
    prefer-ip-address: true
    eureka.instance.ip-address: 127.0.0.1
    instance-id: ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
  client:
    service-url:
      defaultZone: http://127.0.0.1:9090/eureka/

启动 eureka,config,打开 eureka 地址,可以看到 config 配置服务已经注册上来。
Spring Cloud(三)配置服务 Config

相关文章: