Setting up Play 2.4.0 with Postgres and HikariCP yields configuration error

怎甘沉沦 提交于 2019-12-06 06:24:01

There are two places were you can see exactly how to configure your connection pool:

  1. Play docs: SettingsJDBC
  2. play-jdbc reference.conf file

From there, you will can see that your pool must be configured like:

db {
  default {
    driver=org.postgresql.Driver
    url="jdbc:postgresql://localhost/timeseries"
    user=postgres
    password=postgres

    hikaricp {
      dataSourceClassName = org.postgresql.ds.PGSimpleDataSource
      connectionTestQuery = "SELECT 1"
      # Data source configuration options. Must be INSIDE
      # the hikaricp "node" here
      dataSource {
        # anything you need to configure here
        ...
      }
    }
  }
}

Notice how the configuration nodes are nested: db -> default -> hikaricp -> dataSource. That is because dataSource is a configuration specific to HikariCP. As you can see at the reference.conf file, BoneCP does not offer this configuration node.

Also, Typesafe Configuration library supports both this the configuration above or writing more "plainly" like below:

db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost/timeseries"
db.default.user=postgres
db.default.password=postgres
db.default.hikaricp.dataSourceClassName = org.postgresql.ds.PGSimpleDataSource
db.default.hikaricp.connectionTestQuery = "SELECT 1"

Also try:

db.default.hikaricp.dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
db.default.hikaricp.dataSource.user=username
db.default.hikaricp.dataSource.password=password
db.default.hikaricp.dataSource.databaseName=mydb
db.default.hikaricp.dataSource.serverName=localhost

Found the answer:

You need to use this format:

dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
dataSource.user=postgres
dataSource.password=sdfsdfasd
dataSource.databaseName=timeseries
dataSource.serverName=localhost
hikaricp .connectionTestQuery = "SELECT 1"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!