简体   繁体   English

阅读Play for Scala中的application.conf配置

[英]Read application.conf configuration in Play for Scala

I have the following data source configured in application.conf that I use to run Slick statements. 我在application.conf中配置了以下数据源,用于运行Slick语句。

I need to access the same database through an OLAP engine that will use the same user and password. 我需要通过使用相同用户和密码的OLAP引擎访问同一个数据库。

Since it's already configured, I'd like to get these two from there, is it possible to read application.conf from Scala? 既然它已经配置好了,我想从那里得到这两个,是否可以从Scala读取application.conf I know I can read the physical file, but is there a library to get the parsed data? 我知道我可以读取物理文件,但是有一个库来获取解析数据吗?

## JDBC Datasource
# ~~~~~
#

dbConfig = {
  url = "jdbc:mysql://localhost:3306/db"
  driver = com.mysql.jdbc.Driver
  connectionPool = disabled
  keepAliveConnection = true
  user=root
  password=xxxx
}

Working with play, you simply inject the configuration like this: 使用play,你只需注入如下配置:

import javax.inject.Inject
import play.api.Configuration

class Something @Inject()(configuration: Configuration) {
  val url: Option[String] = configuration.getString("dbConfig.url")
  val keepAliveConnection: Option[Boolean] = configuration.getBoolean("dbConfig.keepAliveConnection")

  ...
}

Also see Configuration API on how to get your properties in various types and formats. 另请参阅有关如何以各种类型和格式获取属性的Configuration API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM