2016-07-12 28 views
4

我不能得到光滑與發揮2.5.X工作爲play.api.db.slick.DatabaseConfigProvider沒有實施勢必

我得到以下運行時錯誤:

ProvisionException: Unable to provision, see the following errors: 

1) No implementation for play.api.db.slick.DatabaseConfigProvider was bound. 
    while locating play.api.db.slick.DatabaseConfigProvider 

吾道看起來像:

@Singleton 
class UserDAO @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) 
extends HasDatabaseConfigProvider[JdbcProfile] { 
    import driver.api._ 

... 

} 

而我只是把它注射在我的控制器,如:

@Singleton 
class UserController @Inject() (ws: WSClient, cache: CacheApi, userDAO: UserDAO) extends Controller { 
... 
} 

build.sbt

scalaVersion := "2.11.7" 

libraryDependencies ++= Seq(
    cache, 
    ws, 
    "org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test, 
    // database 
    jdbc, 
    "org.postgresql"  % "postgresql" % "9.3-1102-jdbc41", 
    "com.typesafe.play" %% "play-slick" % "2.0.0" 
) 

我application.conf有:

play.db { 
    # The combination of these two settings results in "db.default" as the 
    # default JDBC pool: 
    #config = "db" 
    #default = "default" 

    # Play uses HikariCP as the default connection pool. You can override 
    # settings by changing the prototype: 
    prototype { 
    # Sets a fixed JDBC connection pool size of 50 
    #hikaricp.minimumIdle = 50 
    #hikaricp.maximumPoolSize = 50 
    } 
} 

## JDBC Datasource 
db { 
    default.driver = org.postgresql.Driver 
    default.url = "jdbc:postgresql://localhost/testdb_development" 
    default.username = "blankman" 
    #default.password = "" 
} 

如果我更改了數據庫的名稱,我得到一個連接錯誤,所以池正確拿起我的配置設置。

回答

2

我可以在application.conf中看到的一個問題是,它錯過了play-slick特定的配置鍵。事實上,你應該從你application.conf刪除分貝部分,如圖https://www.playframework.com/documentation/2.5.x/PlaySlick#database-configuration

你可能想要做的是消除由JDBC依賴的另一件事與slick.dbs更換您的sbt構建文件,就我的知識(基於Play 2.4.x)而言,不能在同一Play項目中同時使用play-slick和jdbc。

我一定建議您閱讀Play-Slick文檔以更好地理解它是如何工作的。

希望這會有所幫助!

0

我解決這個問題,這個配置在application.conf

slick.dbs.default.driver="slick.driver.PostgresDriver$" 
slick.dbs.default.db.url="jdbc:postgresql://127.0.0.1:5432/[name_db]" 
slick.dbs.default.db.user=[name_db] 
slick.dbs.default.db.password=[pw_bd]