【问题标题】:How to access play configuration from a different module如何从不同的模块访问播放配置
【发布时间】:2014-08-13 20:16:36
【问题描述】:

我有一个多模块 sbt 应用程序,其中一个模块是一个播放应用程序。

所以我的模块布局是这样的:

/模块1/ /模块2/ /module-web

现在在我的其他模块中,我正在使用类型安全配置库 (com.typesafe.config)。

现在我有一个模块 module3,它将在我的 module-web (play) 中使用,它也将在另一个项目中使用。我将同步 application.conf 以便在 play 项目和其他项目中都相同。

我的问题是,如何从 module3 内部访问 play application.conf?

module3 没有 play framework 作为依赖,只有 typesaf 配置库。

我知道游戏可以让你做到:

Play.current.configuration.getString("db.driver")

有没有类似但没有使用Play.current 方法的东西?

【问题讨论】:

    标签: scala playframework sbt


    【解决方案1】:

    您可以使用ConfigFactory 类(很可能load 方法会满足您的需求,您也可以查看 parseString/parseFile 方法),然后调用 toConfig():

    import com.typesafe.config.ConfigFactory
    import play.api.Configuration
    
    val config = new Configuration(ConfigFactory.load())
    config.getString("db.driver") ..etc
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 2021-09-26
      相关资源
      最近更新 更多