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

Spring Cloud项目从Github读取远程配置时出现解析异常

解决Spring Cloud Config中YAML配置数据源密码解析错误问题

问题根源在于YAML语法的解析规则:以{开头的字符串会被默认识别为块映射的起始标记,而你的密码值{cipher}encrypted_password恰好以{开头,导致YAML解析器误判结构,抛出"expected , but found "的错误。

给出两种可行解决方案:

方案1:给密码值添加单引号

将密码用单引号包裹,强制YAML解析器将其视为纯字符串,避免结构误判:

spring:
  datasource:
    url: jdbc:oracle:thin:@myserver:port:sid
    username: USER
    password: '{cipher}encrypted_password'

注:单引号不会影响Spring Cloud Config对{cipher}前缀的识别,解密逻辑可正常工作

方案2:转义{字符

在密码的{前添加YAML转义符\,明确标记该字符为普通文本:

spring:
  datasource:
    url: jdbc:oracle:thin:@myserver:port:sid
    username: USER
    password: \{cipher}encrypted_password

说明:之前针对url字段尝试引号操作无效,因为问题的核心不在url,而是password字段的YAML语法冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 17:27:25