【springcloud 】springcloud 本地配置中心和git配置中心的搭建步骤

1.准备配置文件,放在本地和push到git仓库上

磁盘下新建yml配置文件放在自定义目录下

user-service服务 user-service-dev.yml,user-service-test.yml,user-service-prod.yml

pay-service服务 pay-service-dev.yml,pay-service-test.yml,pay-service-prod.yml

 2.配置中心服务config-service的application.yml配置如下

server:
  port: 9501
  
spring:
  application:
    name: config-service

  profiles:
    active: native # 配置中心用本地的话 打开注释 ,用git管理的话就注释掉

  #配置远程git仓库路径
  cloud:
    config:
      server:
# 使用git配置管理配置文件的话打开git节点注释,注释掉下面的native节点,并注释掉上面的profiles节点
#        git:
#          uri:
#          username: root
#          password: root
        native:
          search-locations: E:/pdl/configfile-repertory #本地路径时分隔符别用\

# 配置注册中心
eureka:
  client:
    service-url:
      defaultZone: http://localhost:9500/eureka/

 3.使用的时候,在user-service 和pay-service切换的时候 改下面的profile值就ok了

server:
  port: 9502#测试
      
spring:
  application:
    name: user-service
    
  # 配置中信息服务
  cloud:
    config:
      discovery:
        enabled: true
        service-id: CONFIG-SERVICE
#      profile: test #测试环境
      profile: dev #开发环境

4.验证调试

通过url就可以拿取配置文件信息

例如,想拉取user-service-dev.yml的配置信息

访问链接 

http://localhost:9501/user-service-dev.yml  (主机和端口改为各自的服务即可)

这里注意一点的是,yml文件格式要规范准确,错误的格式也访问不了

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章