You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署带RestClient的Quarkus微服务如何替换application.yaml中的/字符

Quarkus REST Client 兼容Kubernetes ConfigMap 配置方案

问题原因

Quarkus 默认的MicroProfile REST Client 配置key包含/字符,而Kubernetes ConfigMap的key仅允许使用英文字母、数字、-、_、.四类特殊字符,不符合规则的配置会直接提交失败。

可行解决方案

无需修改业务代码中的@RegisterRestClient注解,也不需要硬编码baseUri,直接将配置key中的/替换为.即可,Quarkus原生兼容两种格式的配置key,无需额外适配。

配置示例

替换前的原始配置(存在/字符,无法存入ConfigMap):

# REST Client 原始配置
org:
  acme:
    restclient:
      CountriesService/mp-rest/url: https://restcountries.eu/rest
coreClient/mp-rest/url: <core服务地址>
coreClient/mp-rest/scope: <core服务scope配置>
identityClient/mp-rest/url: <identity服务地址>
identityClient/mp-rest/scope: <identity服务scope配置>

替换后的合法配置(可直接存入ConfigMap):

# 替换斜杠为点号后的合规配置
org:
  acme:
    restclient:
      CountriesService.mp-rest.url: https://restcountries.eu/rest
coreClient.mp-rest.url: <core服务地址>
coreClient.mp-rest.scope: <core服务scope配置>
identityClient.mp-rest.url: <identity服务地址>
identityClient.mp-rest.scope: <identity服务scope配置>

额外可选方案

如果你的配置是通过环境变量注入的,也可以将/替换为全大写的下划线分隔格式,比如coreClient/mp-rest/url对应的环境变量为CORECLIENT_MP_REST_URL,同样可以被Quarkus正常识别。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 01:18:00