Intellij Scala工作表中的类型安全配置库不可用

Intellij Scala工作表中的类型安全配置库不可用,scala,intellij-idea,typesafe-config,Scala,Intellij Idea,Typesafe Config,我使用ficus和typesafe配置来管理配置 我想在本项目中使用Intellij的scala工作表,但当我尝试以下代码时: import what.ever.ApplicationSetting ApplicationSetting.aws.accessKey 但是,我得到以下错误: java.lang.ExceptionInInitializerError at some.thing.A$A11$A$A11.get$$instance$$res0(testRes.sc:3)

我使用ficus和typesafe配置来管理配置

我想在本项目中使用Intellij的scala工作表,但当我尝试以下代码时:

import what.ever.ApplicationSetting

ApplicationSetting.aws.accessKey
但是,我得到以下错误:

java.lang.ExceptionInInitializerError
    at some.thing.A$A11$A$A11.get$$instance$$res0(testRes.sc:3)
    at #worksheet#.#worksheet#(testRes.sc:11)
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'aws'
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:147)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164)
    at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:206)
    at net.ceedubs.ficus.readers.StringReader$$anon$1.read(StringReader.scala:7)
    at net.ceedubs.ficus.readers.StringReader$$anon$1.read(StringReader.scala:6)
    at what.ever.ApplicationSetting$$anon$1.read(ApplicationSetting.scala:24)
application.conf
的内容如下:

package what.ever

import com.typesafe.config.ConfigFactory
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._

object ApplicationSetting {

  val env = sys.env.getOrElse("DEV_ENV", "default")
  val config = {
    ConfigFactory.defaultOverrides
      .withFallback(ConfigFactory.load(env))
      .withFallback(ConfigFactory.load)
  }

  case class AWS(accessKey: String,
                 secretKey: String)

  val aws = config.as[AWS]("aws")

}
我觉得很奇怪,因为同样的代码在scala控制台中也能工作

如有任何建议,我将不胜感激


如果您想测试代码,请签出它。

我发现的一个解决方法是以另一种方式加载配置文件。 首先将配置文件更改为类似于
myAppConf.conf
的格式,以避免配置文件从合并策略中消失

package what.ever

import java.io.File
import com.typesafe.config.ConfigFactory
import net.ceedubs.ficus.Ficus._
import net.ceedubs.ficus.readers.ArbitraryTypeReader._

object ApplicationSetting {

  val confPath = getClass.getResource("/myAppConf.conf") 
  val config = ConfigFactory.parseFile(new File(confPath.getPath)).resolve()

  case class AWS(accessKey: String,
                 secretKey: String)

  val aws = config.as[AWS]("aws")

}

我不能提供太多帮助,但有时当我在Intellij中遇到工作表问题时,我会转到repl,或者更高版本提供了很好的增强repl和加载库的简单方法。Ammonite仍然难以添加类路径。因此,在某些情况下,它不能作为替代品。不过repl还可以。