springcloud-config基本构建-配置中心-创新互联

Spring Cloud Config为所有微服务提供一个统一的外部配置的地方。

为来凤等地区用户提供了全套网页设计制作服务,及来凤网站建设行业解决方案。主营业务为网站建设、做网站、来凤网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

 可以将Spring Cloud Config理解成一个微服务ConfigServce,也是要注册到注册中心euraka中,同时他要与github整合,将配置文件存放到github中,ConfigServce到GitHubs进行拉取,而其他的微服务端到ConfigService上进行获取配置。【ConfigServce也可以用本地作为配置文件的存储仓库,即本项目的property文件】

  接下来是怎么配置出这个ConfigServce服务

1、pom.xml
org.springframework.cloudspring-cloud-config-serverorg.springframework.cloudspring-cloud-starter-netflix-eureka-clientorg.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-actuatororg.springframework.bootspring-boot-devtoolsruntimetrueorg.projectlomboklomboktrueorg.springframework.bootspring-boot-starter-testtest
2、application.yml【一个配置是和git适配的配置、一个是注册到euraka的配置】
server:
  port: 3344
spring:
  application:
    name: config-center
  cloud:
    config:
      server:
        git:
          #仓库地址
          uri: https://github.com/xzjyy/springcloud-config.git
          search-paths:
            - springcloud-config  #要扫描的文件
          username: xzjyy #github的用户名
          #gitHub的令牌
          password: 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
      label: master #分支

eureka:
  client:
    #表示是否将自己注册进EurekaServer默认为true
    register-with-eureka: true
    #是否从EurekaServer抓取已有的注册信息,默认为true。
    #单节点无所谓,集群必须设置为true才能配合ribbon使用负载均衡
    fetch-registry: true
    service-url:
      defaultZone: http://eureka7002.com:7002/eureka/
3、启动类上增加一个配置中心服务的注解   
@EnableConfigServer
4、启动服务,可以用get的请求方式,请求对应配置文件

http://{configService.IP}:{port}http://{configService.IP}:

5、其他服务端增加一个BootStrap.yml文件-读取配置中心信息的配置文件

server:
  port: 3355
spring:
  application:
    name: config-client
  cloud:
    config:
      #分支名称
      label: master
      name: config  #配置文件名称
      profile: dev  #读取后缀名称
      uri: http://localhost:3344 #配置中心地址k
      #上述3个综合:master分支上config-dev.yml的配置文件被读取
      #http://config-3344.com:3344/master/config-dev.yml
eureka:
  client:
    fetch-registry: true
    register-with-eureka: true
    service-url:
      defaultZone: http://eureka7002.com:7002/eureka/

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


网站标题:springcloud-config基本构建-配置中心-创新互联
标题链接:http://ybzwz.com/article/cogici.html