0
我收到了我的application.conf
文件内部的解析异常。路径参数:路径无效Scala播放配置文件
这里是我的application.conf
db.test.driver = org.postgresql.Driver
db.test.user = "postgres"
db.test.password = "postgres"
db.test.url = "jdbc:postgresql://localhost:5432/gasguru"
这里是我试图使用从我application.conf
trait DbConfigWeb extends DbConfig { qualifier: DbQualifier =>
def url: String = current.configuration.getString(qualifier + ".url").get
println(url)
def username: String = current.configuration.getString(qualifier + ".user").get
def password: String = current.configuration.getString(qualifier + ".password").get
def driver: String = current.configuration.getString(qualifier + ".driver").get
override def database: DatabaseDef = JdbcBackend.Database.forURL(url, username, password, null, driver)
override implicit val session = database createSession
}
trait DbQualifier {
val qualifier: String
}
trait DbProductionQualifier extends DbQualifier {
override val qualifier = "db.production"
}
trait DbTestQualifier extends DbQualifier {
override val qualifier = "db.test"
}
这里阅读代码我试图运行测试用例:
class DbConfigWebUnitTest extends PlaySpec with OneAppPerSuite with BeforeAndAfterAll {
"DbConfigWebTest" must {
"have the same username as what is defined in application.conf" in {
val dbManagementWeb = new DbConfigWeb with DbTestQualifier
dbManagementWeb.username must be("postgres")
}
"have the same password as what is defined in application.conf" in {
val dbManagementWeb = new DbConfigWeb with DbTestQualifier
dbManagementWeb.username must be("postgres")
}
"have the qualifier db.test" in {
val dbManagementWeb = new DbConfigWeb with DbTestQualifier
dbManagementWeb.qualifier must be ("db.test")
}
}
}
最后错误信息:
[info] - must have the qualifier db.test *** FAILED ***
[info] com.typesafe.config.ConfigException$BadPath: path parameter: Invalid path 'com.suredbits.web.db[email protected]1e2cbe08.url': Token not allowed in path expression: '$' ('$' not followed by {, '$' not allowed after '$') (you can double-quote this token if you really want it here)
[info] at com.typesafe.config.impl.Parser.parsePathExpression(Parser.java:1095)
[info] at com.typesafe.config.impl.Parser.parsePath(Parser.java:1135)
[info] at com.typesafe.config.impl.Path.newPath(Path.java:224)
[info] at com.typesafe.config.impl.SimpleConfig.hasPath(SimpleConfig.java:80)
[info] at play.api.Configuration.reportError(Configuration.scala:743)
[info] at play.api.Configuration.readValue(Configuration.scala:132)
[info] at play.api.Configuration.getString(Configuration.scala:151)
[info] at com.suredbits.web.db.DbConfigWeb$class.url(DbConfigWebProduction.scala:14)
[info] at com.suredbits.web.db.DbConfigWebUnitTest$$anonfun$1$$anonfun$apply$mcV$sp$3$$anon$3.url(DbConfigWebUnitTest.scala:27)
[info] at com.suredbits.web.db.DbConfigWeb$class.$init$(DbConfigWebProduction.scala:15)
[info] ...