Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Postgres和HikariCP设置Play 2.4.0会产生配置错误_Java_Postgresql_Playframework_Datasource_Hikaricp - Fatal编程技术网

Java 使用Postgres和HikariCP设置Play 2.4.0会产生配置错误

Java 使用Postgres和HikariCP设置Play 2.4.0会产生配置错误,java,postgresql,playframework,datasource,hikaricp,Java,Postgresql,Playframework,Datasource,Hikaricp,我正在尝试设置一个play framework服务器,并连接到本地postgres 我当前的applications.conf如下所示: dbplugin=disabled db { default { dataSourceClassName=org.postgresql.ds.PGSimpleDataSource dataSource { user="postgres" password="postgres" databaseName="

我正在尝试设置一个play framework服务器,并连接到本地postgres

我当前的
applications.conf
如下所示:

dbplugin=disabled
db {
  default {
    dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
    dataSource {
      user="postgres"
      password="postgres"
      databaseName="timeseries"
      serverName="localhost"
    }
    hikaricp {
      connectionTestQuery = "SELECT 1"
    }
  }
}
My build.sbt只添加了最新的用于postgres的jdbc:

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  javaJdbc
  , cache
  , javaWs
  , "org.postgresql" % "postgresql" % "9.4.1207.jre7"
)
我收到的错误是

[error] - application - 
[info] 
[info] ! @6ookeg34l - Internal server error, for (GET) [/] ->
[info]  
[info] play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:
[info] 
[info] 1) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [default]]
[info]   while locating play.api.db.DBApiProvider
[info]   while locating play.api.db.DBApi
[info]     for parameter 0 at play.db.DefaultDBApi.<init>(DefaultDBApi.java:28)
[info]   at play.db.DefaultDBApi.class(DefaultDBApi.java:28)
[info]   while locating play.db.DefaultDBApi
[info]   while locating play.db.DBApi
[info]     for field at play.db.DBModule$NamedDatabaseProvider.dbApi(DBModule.java:61)
[info]   while locating play.db.DBModule$NamedDatabaseProvider
[info]   at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
[info]   at play.db.DBModule.bindings(DBModule.java:40):
[info] Binding(interface play.db.Database qualified with QualifierInstance(@play.db.NamedDatabase(value=default)) to ProviderTarget(play.db.DBModule$NamedDatabaseProvider@3782a5cb)) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$1)
[info] Caused by: Configuration error: Configuration error[Cannot connect to database [default]]
[错误]-应用程序-
[信息]
[信息]@6ookeg34l-内部服务器错误,用于(GET)[/]->
[信息]
[info]play.api.UnexpectedException:意外异常[CreationException:无法创建注射器,请参阅以下错误:
[信息]
[信息]1)自定义提供程序中出错,配置错误:配置错误[无法连接到数据库[默认]]
[信息]查找play.api.db.dbaprovider时
[信息]查找play.api.db.DBApi时
[info]用于play.db.DefaultDBApi处的参数0。(DefaultDBApi.java:28)
[info]at play.db.DefaultDBApi.class(DefaultDBApi.java:28)
[信息]查找play.db.DefaultDBApi时
[信息]查找play.db.DBApi时
[info]用于field at play.db.DBModule$NamedDatabaseProvider.dbApi(DBModule.java:61)
[信息]查找play.db.DBModule$NamedDatabaseProvider时
[信息]位于com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
[info]at play.db.DBModule.bindings(DBModule.java:40):
[info]绑定(接口play.db.Database,使用限定符instance(@play.db.namedatabase(value=default))限定)到ProviderTarget(play.db.DBModule$NamedDatabaseProvider@3782a5cb))(通过modules:com.google.inject.util.modules$OverrideModule->play.api.inject.guice.GuiceableModuleConversions$$anon$1)
[信息]原因:配置错误:配置错误[无法连接到数据库[默认]]
我已经发现,我的play 2.4不需要hikari作为显式依赖项。另外,密码和用户名以及数据名都是正确的

除了框架网站之外,我实际上不知道在哪里可以找到更多信息,我已经广泛地检查了这两个网站。似乎有很多人都有类似的问题,尽管他们的解决方案对我没有帮助,或者只是我前进了一步。

找到了答案:

您需要使用以下格式:

dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
dataSource.user=postgres
dataSource.password=sdfsdfasd
dataSource.databaseName=timeseries
dataSource.serverName=localhost
hikaricp .connectionTestQuery = "SELECT 1"
还可以尝试:

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

您可以在两个地方看到如何配置连接池:

  • 从这里,您可以看到您的池必须按如下方式配置:

    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
            ...
          }
        }
      }
    }
    
    注意配置节点是如何嵌套的:
    db
    ->
    默认值
    ->
    hikaricp
    ->
    dataSource
    。这是因为
    dataSource
    是特定于hikaricp的配置。正如您在
    reference.conf
    文件中看到的,BoneCP不提供此配置节点

    此外,支持上述配置或更“清晰”地编写以下内容:

    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"
    

    非常感谢!我真的很感激它(尽管我已经找到了我的答案)。我花了很长时间才掌握了所有的娱乐资源。IRC的人自己也没那么乐于助人,只是被动进取。所以我真的很感谢你!