Spring Cloud 2-Config 分布式配置中心(七)


Spring Cloud  Config 

 

  • 1.github配置
  • 2.服务端配置
    • pom.xml
    • application.xml
    • Application.java
  • 3.配置和命名
    • 1. 配置加载顺序
    • 2. 客户端命名规则
  • 4.客户端配置
    • pom.xml
    • application.yml
    • Controller.java
  • 5.获取远程配置
    • 1.访问服务端
    • 2.访问客户端
  • 6.修改配置
    • 1.访问服务
    • 2.访问客户端

 

 


服务架构

 

http://localhost:8888/lyf/dev

{
  "name": "lyf",
  "profiles": [
    "dev"
  ],
  "label": null,
  "version": "9dd38a778c9b4ec9d7b8e972aeabe749e24e0161",
  "state": null,
  "propertySources": [
    {
      "name": "https://github.com/xianghaizing/spring-cloud-learn/config-repo/lyf-dev.properties",
      "source": {
        "from": "local-dev"
      }
    },
    {
      "name": "https://github.com/xianghaizing/spring-cloud-learn/config-repo/lyf.properties",
      "source": {
        "from": "local"
      }
    }
  ]
}
http://localhost:8030/from

local-dev

http://localhost:8888/lyf/dev

{
  "name": "lyf",
  "profiles": [
    "dev"
  ],
  "label": null,
  "version": "a89342009a315c78671b31a35392158673828bba",
  "state": null,
  "propertySources": [
    {
      "name": "https://github.com/xianghaizing/spring-cloud-learn/config-repo/lyf-dev.properties",
      "source": {
        "from": "local-dev-02"
      }
    },
    {
      "name": "https://github.com/xianghaizing/spring-cloud-learn/config-repo/lyf.properties",
      "source": {
        "from": "local"
      }
    }
  ]
}
http://localhost:8030/from
local-dev

此时客户端并没有拿到最新配置,需要手动发送post请求执行刷新

POST http://localhost:8030/actuator/refresh
[
"config.client.version",
"from"
]

再次访问

GET http://localhost:8030/from
local-dev-02