初次使用spring config server client eureka,以及遇到的各种坑

本文记录了在配置Spring Cloud Eureka服务注册与Config Server客户端过程中遇到的问题及解决方案。从本地启动Eureka服务到配置Server端的pom.xml、启动类与应用配置,再到Client端的bootstrap.yml设置,分析了配置中的关键点和易错项。最终在测试中发现,日志中显示的成功并不意味着实际配置成功,提醒读者不要被表面现象迷惑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.首先本地启动一个eureka服务

http://localhost:8763/eureka/
使用浏览器访问的话不能加/eureka这个后缀。使用下面的地址:
http://localhost:8763/

二.配置server服务端

说明一下:我是使用公司的已经写好的配置,就是开始的时候不懂各个配置的含义,导致在写client端出现各种问题,特发表文章记录一下。
直接上代码:

pom.xml

其中eureka包是spring版本问题,所以引用方式不一样
actuator这个包是用来实时更新配置的
这里插入图片描述

启动类添加注解

@SpringBootApplication
@EnableDiscoveryClient
@EnableConfigServer
在这里插入图片描述

application-dev.yml

server:
  port: 8888

eureka:
  instance:
    hostname: spring-cloud-config
    prefer-ip-address: true
  client:
    registerWithEureka: true
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://localhost:8763/eureka/

spring:
  application:
    name: spring-cloud-config
  profiles:
    active: git #设置使用本地配置(默认是git,可以设置:subversion(SVN)native(本地))
  cloud:
    client:
      hostname: spring-cloud-config
    config:
      label: master
      monitor:
        endpoint:
          path: /config
      server:
        prefix: /config #这里配置了前缀,那么你访问的时候就要加上这个前缀
        encrypt:
          enabled: true #这里询问是否要加密,注意:要为true,为false的话client端无法连接成功,具体原因还待后续研究
        monitor:
          github:
            enabled: true
        git:
          uri: http://10.72.76.54/liu/my-gitlab-test.git     # 配置git仓库的地址(最后不需要带/,否则会出现:No custom http config found for URL: XXX)
          cloneOnStart: true
          username: 
          search-paths: config
          password: 
          basedir: target/configs
          accessToken:                                            # git仓库的密码(公开仓库无需账号信息)
          
encrypt:
  key: tenxcloud-configserver-encrypt-key

management:
  endpoints:
    web:
      exposure:
        include: env,bus-refresh
      base-path: /

eureka显示页面

可以看到已经注册成功了
在这里插入图片描述

三.config client端

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值