2016-01-21 71 views
2

我試圖設置一個連接到本地postgres的播放框架服務器。設置使用Postgres和HikariCP播放2.4.0產生配置錯誤

我現在applications.conf是這樣的:

dbplugin=disabled 
db { 
    default { 
    dataSourceClassName=org.postgresql.ds.PGSimpleDataSource 
    dataSource { 
     user="postgres" 
     password="postgres" 
     databaseName="timeseries" 
     serverName="localhost" 
    } 
    hikaricp { 
     connectionTestQuery = "SELECT 1" 
    } 
    } 
} 

我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([email protected])) (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]] 

我已經發現,我的遊戲2.4不需要光照作爲明確的依賴關係。 Additonally密碼和用戶名是正確的以及databsename。

我實際上並不知道除了框架的網站以外還有哪些地方需要尋找更多的信息,並且我已經廣泛地進行了檢查。多人似乎也遇到了類似的問題,儘管他們的解決方案並沒有幫助我,或者僅僅是我迄今爲止的一步。

回答

3

有兩個地方是你可以清楚地看到如何配置你的連接pool:

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

從那裏,你將可以看到你的池必須像進行配置:

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 - >default - >hikaricp - >dataSource。這是因爲dataSource是HikariCP特有的配置。正如您在reference.conf文件中所見,BoneCP不提供此配置節點。

此外,Typesafe Configuration library同時支持這上面的配置或寫更多的「明明白白」象下面這樣:

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" 
+0

非常感謝您!我真的很喜歡它(儘管我已經找到了答案)。我花了很長時間纔得到了所有的遊戲資源。 IRC中的人對他們本身沒有幫助,只是被動的侵略。所以我非常感謝你! – awildturtok

0

找到了答案:

您需要使用以下格式:

dataSourceClassName=org.postgresql.ds.PGSimpleDataSource 
dataSource.user=postgres 
dataSource.password=sdfsdfasd 
dataSource.databaseName=timeseries 
dataSource.serverName=localhost 
hikaricp .connectionTestQuery = "SELECT 1" 
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