You need to enable JavaScript to run this app. Spring Boot从Spring Config Server读配置时IdComercioMT值异常
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot从Spring Config Server读配置时IdComercioMT值异常

Spring Cloud Config 配置值读取异常场景

基础实现代码

配置属性类

类上标注@RefreshScope、@Configuration、@Getter注解,通过@Value绑定配置项,具体代码如下:

@RefreshScope
@Configuration
@Getter
public class ConfigProperties {

   @Value("${receipts.Application}")
   private String application;
   @Value("${receipts.ApplicationIdMT}")
   private String applicationIdMT;
   @Value("${receipts.IdComercioMT}")
   private String idComercioMT;
   // 其余属性配置省略
}

Git仓库托管的配置内容

项目将application.yml托管在Git仓库,由Spring Config Server对外提供配置拉取能力,仓库中对应配置片段为:

receipts:
   Application: NAVERU
   ApplicationIdMT: b96f9c62-e6a
   IdComercioMT: 02500000012
   # 其余配置项省略

业务类读取逻辑

在ClientBase类中通过@Autowired注入配置类,直接调用get方法获取属性值并打印,核心代码如下:

// 省略相关导入、通用业务逻辑
public class ClientBase {

    @Autowired
    protected ConfigProperties configProperties;

    public void printValues(){
        String application= configProperties.getApplication();
        String applicationIdMT= configProperties.getApplicationIdMT();
        String idComercioMT= configProperties.getIdComercioMT();
        System.out.println("aplication: "+application);
        System.out.println("idMt: "+applicationIdMT);
        System.out.println("idComerceMt: "+idComercioMT);
    }
}

异常表现

应用运行后控制台实际输出为:

aplication: NAVERU
idMt: b96f9c62-e6a
idComerceMt: 352321546

对比Git仓库的配置值可见:

  • receipts.Application配置值为NAVERU,实际读取值为NAVERU,与配置源匹配
  • receipts.ApplicationIdMT配置值为b96f9c62-e6a,实际读取值为b96f9c62-e6a,与配置源匹配
  • receipts.IdComercioMT配置值为02500000012,实际读取值为352321546,与配置源完全不符

目前该异常暂未定位到明确根因,仅单条配置出现读取偏移,其余配置项均能正常加载。


内容的提问来源于stack exchange,提问作者Juan Sanchez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.30 22:54:03