Mysterious Play 2.4 Injection exception
Asked Answered
N

2

7

Recently upgraded to Play 2.4 and I'm still learning all the little quirks and such. I'm trying to just get my index page working and I'm having a hard time of it, and I know it's something small I'm missing. Here is the error

CreationException: Unable to create injector, see the following errors:

1) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [default]]
  while locating play.api.db.DBApiProvider
  while locating play.api.db.DBApi
    for parameter 0 at play.db.DefaultDBApi.<init>(DefaultDBApi.java:28)
  at play.db.DefaultDBApi.class(DefaultDBApi.java:28)
  while locating play.db.DefaultDBApi
  while locating play.db.DBApi
    for field at play.db.DBModule$NamedDatabaseProvider.dbApi(DBModule.java:61)
  while locating play.db.DBModule$NamedDatabaseProvider
  at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149)
  at play.db.DBModule.bindings(DBModule.java:40):

And my configuration information (yes that port number for mysql is correct)

application.conf

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql:localhost:33060/coffee_bean"
db.default.username=
db.default.password=""
ebean.default = ["models.*"]

Main controller

public Result index() {
        ObjectNode response = Json.newObject();
        Configuration config = Play.application().configuration();
        response.put(config.getString("coffee.bean.message.key"),config.getString("coffee.bean.success.message"));
        response.put(config.getString("version"), config.getString("coffee.bean.version"));

        return ok(response);
    }

built.sbt

name := """coffee-bean"""

version := "1.0-SNAPSHOT"

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

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,
  "mysql" % "mysql-connector-java" % "5.1.36",
  evolutions
)

// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
lazy val myProject = (project in file("."))
  .enablePlugins(PlayJava, PlayEbean)

plugins.sbt

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")

// Web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")

// Play enhancer - this automatically generates getters/setters for public fields
// and rewrites accessors of these fields to use the getters/setters. Remove this
// plugin if you prefer not to have this feature, or disable on a per project
// basis using disablePlugins(PlayEnhancer) in your build.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(SbtEbean). Note, uncommenting this line will automatically bring in
// Play enhancer, regardless of whether the line above is commented out or not.
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.0")

Anything else you need to see?

So far I've tried just reimporting dependencies, double checking to make sure version are right, going through the documentation again, and so far nothing has worked. I'm expecting a certain user will have all the answers :)

Nabonidus answered 6/7, 2015 at 10:57 Comment(0)
M
2

Database connection configuration is missing.

Define it in conf\application.conf:

db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/playdb"
db.default.username=playdbuser
db.default.password="a strong password"
Marilynnmarimba answered 7/7, 2015 at 1:11 Comment(3)
You've definitely pointed me in the right direction. I had written my connection string wrong >.<Nabonidus
Although changing the connection info to be correct, I still can't connect. Do you know if there are any other settings to set? I feel like such a moron now >.<Nabonidus
User and password for mysql database should be set. This link will help you reset root password for mysl: Mysql: How to Reset the Root PasswordMarilynnmarimba
G
0

My config:

<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <non-jta-data-source>caribbeanDS</non-jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
        </properties>
    </persistence-unit>

</persistence>

My code:

version := "1.0-SNAPSHOT"

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

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,
  javaJpa,
  "org.hibernate" % "hibernate-entitymanager" % "4.3.10.Final" // replace by your jpa implementation
)


// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator


fork in run := true


# Default database configuration using MySQL database engine
# Connect to playdb as playdbuser
db.caribbean.driver=com.mysql.jdbc.Driver
db.caribbean.url="jdbc:mysql://localhost:8889/bahamasnet"
db.caribbean.username=root
db.caribbean.password="root"

db.caribbean.jndiName=caribbeanDS

jpa.default=defaultPersistenceUnit
Gabriellia answered 15/7, 2015 at 0:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.