Can't connect play 2.5 to mysql

2,458 views
Skip to first unread message

Chet

unread,
Mar 13, 2016, 12:30:50 PM3/13/16
to play-framework
Hello I have an older version of play running and connecting to mysql without a problem. however I am trying to setup a new Play 2.5 site and I can't get it to work. I can connect to the database without a problem via phpmyadmin. However Play gives a configuration error, I don't know if it is me or the new version.

The error..
Caused by: java.lang.IllegalArgumentException: either dataSource or dataSourceClassName is required

My build.sbt contains...
libraryDependencies ++= Seq(
  "com.feth" %% "play-authenticate" % "0.7.1",
  "mysql" % "mysql-connector-java" % "5.1.34",
  javaJdbc,
  cache,
  javaWs
)

and application.conf contains..
db {
  # You can declare as many datasources as you want.
  # By convention, the default datasource is named `default`

  # https://www.playframework.com/documentation/latest/Developing-with-the-H2-Database
  default.driver = org.h2.Driver
  default.url = "jdbc:h2:mem:play"
  default.username = sa
  default.password = ""

  # You can turn on SQL logging for any datasource
  # https://www.playframework.com/documentation/latest/Highlights25#Logging-SQL-statements
  default.logSql=true

  db.test.url="jdbc:mysql://localhost/test?characterEncoding=UTF-8"
  db.test.driver=com.mysql.jdbc.Driver
  db.test.user=testUser
  db.test.pass=testPassword
}

I have been unable to figure this out, What am I missing?

Luo William

unread,
May 31, 2016, 5:20:45 AM5/31/16
to play-framework
I met the same issue, but fixed today.

In application.conf file, uncomment the following,
play.db {
# The combination of these two settings results in "db.default" as the
# default JDBC pool:
config = "db"
default = "default"

also,

you need set like this,

default.driver=com.mysql.jdbc.Driver
default.url="jdbc:mysql://127.0.0.1/xxx?characterEncoding=UTF-8"
default.username=root
default.password="root"

don't need db., since you already in the db set range.


在 2016年3月14日星期一 UTC+8上午12:30:50,Chet写道:

Potter Chains

unread,
Jun 16, 2016, 1:22:47 AM6/16/16
to play-framework
Thank you!

it worked for me.

i didn't know how to resolve it because i was following the turorial and i thought i was doing something wrong.

thaks a lot!!!
Message has been deleted

Jasondf

unread,
Jun 22, 2016, 7:35:04 AM6/22/16
to play-framework

Thank you,  I got this same problem, and this works for me.


prakash chandra Pandey

unread,
Jul 10, 2016, 4:48:23 PM7/10/16
to play-framework
Hey,
whoever you are thank you so much.
Reply all
Reply to author
Forward
0 new messages