Scala没有找到配置密钥

时间:2017-08-05 15:44:25

标签: scala

我可以提取

的价值
val ranking_score_path = cf.getString(stg + ".input.path.ranking_score")
  .replaceAll("_replace_date_", this_date)

val output_path = cf.getString(stg + ".output.path.hdfs") + tomz_date + "/"

但不是

val AS_HOST = cf.getString(stg + ".output.path.aerospike.host")
println("AS_HOST = " + AS_HOST)

我试过了

  1. 替换。用_,
  2. 添加逗号
  3. 但没有工作。

    错误日志

    Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'production.output.path.aerospike'
        at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:152)
        at ...
    

    application.conf

    production {
      input {
        path {
          local = "/home/aduser/tmp/"
          hdfs = "/user/aduser/tmp_vincent/CPA/_replace_date_/intermediate/l1/"
          ranking_score = "/home/aduser/plt/item_performance/pipeline/cpa/output/_replace_date_/predict_output/ranking_score.csv"
        }
      }
      output {
        path {
          local = "/home/aduser/tmp/"
          hdfs = "/user/aduser/dyson/display/"
          aerospike {
            host = "0.0.0.0"
            port = 3000
            namespace = "test"
            set = "spark-test2"
          }
        }
      }
    }
    

    回复@评论#1

    cf很长但重要的部分如下

    ... ore.csv"}},"output":{"path":{"hdfs":"/user/aduser/dyson/display/","local":"/home/aduser/tmp/"}}},"sun":{"arch": ...
    

    努力#1:取代了部分application.conf

        path {
              local = "/home/aduser/tmp/"
              hdfs = "/user/aduser/dyson/display/"
              ae_host = "0.0.0.0"
              ae_port = 3000
              ae_namespace = "test"
              ae_set = "spark-test2"
            }
    

    并更改了调用方法

    val AS_HOST = cf.getString(stg + ".output.path.ae_host")
    println("AS_HOST = " + AS_HOST)
    

    但仍然出现错误

    Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'production.output.path.ae_host'
    at com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:152)
    

1 个答案:

答案 0 :(得分:0)

我在几个小时后发现了问题,我的application.conf与src.main.scala处于同一级别,并且由于我不知道的原因而部分工作。在创建src.main.resources并将application.conf放入其中后,它完美地工作。