springcloud-Config配置中心搭建

  新建一个模块作为配置中心。具体步骤如下:

  1. 新建一个模块

  2. 加入依赖:

复制代码
       《主要是这个依赖》 
    <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>cn.aib.springcloud</groupId> <artifactId>springclud-api-common</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
复制代码

  3.添加配置(配置中心也算是一个服务模块,也得注册到注册中心上)

复制代码
server:
  port: 3344
spring:
  application:
    name: cloud-config-center
  cloud:
    config:
      server:
        git:
          uri: https://github.com/XueWen-Yellow/springcloud-config.git //这个是配置文件所在的仓库的地址
          search-paths:
            - springcloud-config  //这个是仓库名
      label: master  //哪个分支,虽然github上面已经是main分支了,目前master还能配置

eureka:
  client:
    service-url:
      defaultZone: http://localhost:7001/eureka
复制代码

  4.主启动

@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigApplication.class, args);
    }
}

  5.测试。可以访问config暴露出来的接口来获取配置信息,比如:http://localhost:3344/main/config-test.yml;之前是master,现在访问必须是main了

  至于这个访问的URI规则,如下:

 

 

 

posted @   爱编程DE文兄  阅读(127)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示