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

调试CassandraDaemon时遇Invalid yaml错误,求解决方案

问题场景

在CentOS7虚拟机上使用IntelliJ IDEA调试CassandraDaemon(按官方开发文档指导修改源码)时,启动报错:

Invalid yaml: file:/home/cjx/Downloads/depart0/depart-main/conf/cassandra.yaml
 Error: null; Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=java.lang.reflect.InvocationTargetException;  in 'reader', line 10, column 1:
    cluster_name: 'Test Cluster'
    ^
Exception (org.apache.cassandra.exceptions.ConfigurationException) encountered during startup: Invalid yaml: file:/home/cjx/Downloads/depart0/depart-main/conf/cassandra.yaml
 Error: null; Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=java.lang.reflect.InvocationTargetException;  in 'reader', line 10, column 1:
    cluster_name: 'Test Cluster'
    ^
19:29:07.494 [main] ERROR o.a.c.service.CassandraDaemon - Exception encountered during startup: Invalid yaml: file:/home/cjx/Downloads/depart0/depart-main/conf/cassandra.yaml
 Error: null; Can't construct a java object for tag:yaml.org,2002:org.apache.cassandra.config.Config; exception=java.lang.reflect.InvocationTargetException;  in 'reader', line 10, column 1:
    cluster_name: 'Test Cluster'
    ^

但通过命令行执行./cassandra可正常启动Cassandra。

解决办法
  • 修正IDE工作目录配置
    确保IDE运行CassandraDaemon时的工作目录为Cassandra项目根目录(即./cassandra脚本所在目录)。YAML文件中的相对路径(如数据目录、日志目录)依赖工作目录,路径错误会触发配置加载时的反射调用异常。
    操作:在IDEA的Run/Debug Configurations中,找到CassandraDaemon的配置项,将Working directory修改为你的Cassandra项目根目录(示例:/home/cjx/Downloads/depart0/depart-main)。

  • 校验依赖与项目缓存
    命令行启动依赖打包后的完整环境,而IDE调试可能存在依赖缺失或版本不一致:

    1. 重新执行Cassandra构建脚本(如./gradlew build -x test),确保所有依赖正确下载并导入IDE。
    2. 执行IDEA菜单File -> Invalidate Caches...,重启IDE后重新加载项目。
  • 检查配置文件权限
    确认IDE进程拥有cassandra.yaml文件的读取权限。命令行用当前用户权限启动,IDE可能以不同权限运行,执行chmod 644 /home/cjx/Downloads/depart0/depart-main/conf/cassandra.yaml确保文件可读。

  • 重新编译项目
    该错误本质是Config类实例化时反射调用失败,可能是IDE编译输出异常:

    1. 检查IDEA编译目录(默认out或build/classes),确保Config类编译文件为最新版本且无编译错误。
    2. 执行IDEA菜单Build -> Rebuild Project,重新编译整个项目后再启动调试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 00:50:40