Can't connect to mysql database with play-slic

2019-02-28 02:11发布

I'm trying to migrate from anorm to slick, using play 2.4.2, and getting a configuration error:

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [dethcs]]
    at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.0.jar:2.4.0]
...
Caused by: slick.SlickException: Error getting instance of Slick driver "slick.driver.MySQLDriver"
...
Caused by: java.lang.NoSuchMethodException: slick.driver.MySQLDriver.<init>()

Previous answers I've found on SO have focused on having the right MySQL driver and other dependencies. I believe my build.sbt covers the relevant bases, including:

libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.36"
libraryDependencies += "com.typesafe.play" %% "play-slick" % "1.0.1"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "1.0.1"

The relevant lines in my application.conf are:

slick.dbs.dethcs.db.driver="com.mysql.jdbc.Driver"
slick.dbs.dethcs.driver="slick.driver.MySQLDriver"
slick.dbs.dethcs.user="redacted"
slick.dbs.dethcs.db.url="jdbc:mysql://localhost/mydb"
slick.dbs.dethcs.password="redacted"

I'd be grateful for any suggestions as to how to fix this -- I'm guessing it's something silly but I've found it very difficult to get documentation and examples that are specific to more recent versions of slick -- and could provide additional info if that would help.

1条回答
可以哭但决不认输i
2楼-- · 2019-02-28 02:47

I haven't tried myself, but it looks like you are referencing the MySQLDriver class instead of the corresponding object. Put a trailing $ in it and you should be good to go:

slick.dbs.dethcs.driver="slick.driver.MySQLDriver$"

查看更多
登录 后发表回答