IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

Spring Cloud Config 分布式配置中心

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

Spring Cloud Config 简介

在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件。

Spring Cloud 中,有分布式配置中心组件 Spring Cloud Config ,它支持配置服务放在配置服务的内存中(即本地),也支持放在远程 Git 仓库中。

Spring Cloud Config 组件中,分两个角色,一是服务端 Config Server ,二是客户端 Config Client

Spring Cloud Config 服务端

引入依赖

pom.xml 中主要添加 spring-cloud-starter-netflix-eureka-serverspring-cloud-config-server 依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-config-server</artifactId>
</dependency>

相关配置

需要在 bootstrap.yml 中配置,原因是可以优先加载配置。

spring:
  cloud:
    config:
      label: {git仓库标签}
      server:
        git: 
          uri: {git仓库地址}
          search-paths: {仓库内文件存放路径}
          username: {用户名}
          password: {密码}

配置说明:

  • spring.cloud.config.label:配置仓库的分支
  • spring.cloud.config.server.git.uri:配置 Git 仓库地址(GitHub、GitLab、Gitee …)
  • spring.cloud.config.server.git.search-paths:配置仓库路径(存放配置文件的目录)
  • spring.cloud.config.server.git.username:访问 Git 仓库的账号
  • spring.cloud.config.server.git.password:访问 Git 仓库的密码

注意:如果使用 GitLab 作为仓库的话,spring.cloud.config.server.git.uri 需要在结尾加上 .git,GitHub 则不用。

在 Git 仓库中创建配置文件存放目录

在Git 仓库中创建文件夹,用于存放各个服务的资源配置文件。

一般在开发环境中,都会独立出一个 Git 项目用来存放资源配置配置文件。

HTTP 请求配置文件示例

  • http://{ip}:{port}/{applicationName}/{profile}[/{label}]
  • http://{ip}:{port}/{applicationName}-{profile}.yml
  • http://{ip}:{port}/{label}/{applicationName}-{profile}.yml

Spring Cloud Config 客户端

引入依赖

hello-spring-cloud-netflix-eureka 工程的 pom.xml 中添加 spring-cloud-starter-config 依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

创建云配置文件

在 Git 仓库中存放配置文件的目录下创建 hello-spring-cloud-netflix-eureka-dev.yml

spring:
  application:
    name: hello-spring-cloud-netflix-eureka

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

本地配置

修改 hello-spring-cloud-netflix-eureka 工程的 applicaiton.ymlbootstrap.yml 并清空文件

bootstrap.yml 中添加 spring-cloud-config 客户端的配置

spring:   
  cloud:     
    config:       
      uri: http://localhost:8888       
      name: hello-spring-cloud-netflix-eureka-dev       
      label: master       
      profile: dev

配置说明:

  • spring.cloud.config.uri:配置服务中心的网址
  • spring.cloud.config.name:配置资源配置文件名称(不含后缀)
  • spring.cloud.config.label:配置仓库的分支
  • spring.cloud.config.profile:配置文件的环境标识
    • dev:表示开发环境
    • test:表示测试环境
    • prod:表示生产环境

测试云配置

文章永久链接:https://tech.souyunku.com/?p=23947


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(95) 打赏



未经允许不得转载:搜云库技术团队 » Spring Cloud Config 分布式配置中心

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367