当前位置: 首页 > news >正文

嘉兴网站建设方案咨询网站在线支付接口

嘉兴网站建设方案咨询,网站在线支付接口,比较好的企业网站,金昌市建设工程质量监督站网站目录 一、问题现象 二、解决方案 三、运行结果 四、代码地址 一、问题现象 springcloud configClient获取configServer信息失败导致启动configClient注入失败 报错堆栈信息 org.springframework.beans.factory.BeanCreationException: Error creating bean with name scop…

目录

一、问题现象

二、解决方案

三、运行结果

四、代码地址


一、问题现象

springcloud configClient获取configServer信息失败导致启动configClient注入失败

报错堆栈信息

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.testController': Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'version' in value "${version}"

Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'version' in value "${version}"

二、解决方案

经排查,原因为gitee配置文件名config-dev.properties与服务注册名不一致导致,bootstrap.yml配置了configServer地址之后,configClient从gitee中获取配置文件的时候指定了profile(dev哪个环境)以及label(newBranch4分支),但是configServer获取配置文件的时候会批量加载所有分支的配置文件信息,因此configClient和configServer配置文件关联必须由服务名以及文件名关联,因此在修改gitee中配置文件的文件名为服务名之后,configClient启动成功,并成功获取gitee中相关配置信息。

gitee中配置文件内容

git clone https://gitee.com/fzggz/springcloud.git

configServer工程的bootstrap.yml

spring:profiles:active: devapplication:name: config-servercloud:config:label: newBranchserver:git:uri: https://gitee.com/fzggz/springcloudsearchPaths: spring-cloud-config-filetimeout: 60username: ***password: ***default-label: newBranch
eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/
bobo:user:name: boboage: 18

configClient的bootstrap.yml

spring:application:name: config-clientcloud:config:uri: http://127.0.0.1:8030  # 直接连接 Config-Serverprofile: devlabel: newBranch3discovery:enabled: false
#        enabled: true
#        service-id: config-server
eureka:client:serviceUrl:defaultZone: http://localhost:8761/eureka/

三、运行结果

configClient配置客户端代码,启动configClient后,读取configServer中读取到的配置文件信息,通过文件名,profile,label等映射关系找到version,通过@Value注入version,controller中获取

package com.ggz.configclient.controller;import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;/*** @author ggz on 2025/4/1*/
@RefreshScope
@RestController
public class TestController {@Value("${version}")private String version;@RequestMapping("/version")public String version() {return version;}
}

四、代码地址

直接导入,启动eureka和configServer以及configClient即可

https://github.com/GeGuozhi/SpringCloudDemo.git

希望有用的同时大家能帮忙能点亮一个小小的star

http://www.dtcms.com/a/593078.html

相关文章:

  • 【Vue】第五篇
  • 联合索引的最左前缀原则与失效场景
  • solidity中的抽象合约
  • 去中心化铸就价值基石:CVC与BTC引领区块链投资新范式
  • 微美全息(NASDAQ:WIMI)基于边缘云计算与区块链的数据缓存算法,引领数据管理变革
  • K8S RD: Kubernetes核心概念与故障排查全解析
  • 响应式网站手机端广州网站建设商城建设
  • 第三方应用软件提权之vnc提权
  • iOS 跨平台开发实战指南,从框架选择到开心上架(Appuploader)跨系统免 Mac 发布全流程解析
  • 【Go】并发编程的核心思想 CSP 模型
  • 《Vue项目开发实战》第四章:组件封装--ToolBar
  • Redis拒绝策略
  • iphone Delta模拟器如何从夸克网盘导入游戏ROM 附游戏资源下载
  • 专业网站建设平台网站建设功能评估表
  • 做农业网站怎么赚钱58同城北京网站建设
  • 如何在命令行中调用Dev-C++的编译器?
  • C语言自定义类型:联合体与枚举
  • 在线网站推广工具WordPress 付费下载阅读
  • Windows2008 如何禁用FSO?
  • 了解一下LSTM:长短期记忆网络(改进的RNN)
  • 【微服务 - easy视频 | day03】服务与服务之间的调用
  • 网站建设定做mvc网站建设的实验报告
  • CMP(类Cloudera CMP 7 404版华为Kunpeng)告别CDH/CDP,拥抱自主可控的新时代
  • 生成ios钱包pkpass文件
  • Paimon——官网阅读:理解文件
  • 做网站应该学什么语言网站建设裕鸿国际
  • Xenium数据分析 | 使用Xenium Ranger重新分析数据
  • MySQL 8.0 新特性详解:窗口函数,开启数据分析的潘多拉魔盒
  • 基于模板匹配的数字和大写字母识别(Matlab)
  • 网站编程赚钱企业门户网站 php