错误配置数据库mysql与播放框架

时间:2018-02-08 11:27:07

标签: java mysql playframework-2.6

我从Java和Play Framework开始,我尝试配置数据库mysql。 但我有以下错误:

ProvisionException: Unable to provision, see the following errors: 1) No implementation for play.db.Database annotated with @play.db.NamedDatabase(value=baseplay) was bound. 

我有我的班级:

    // inject "orders" database instead of "default"
@javax.inject.Singleton
public class JavaApplicationDataBase implements IWidgetRepository {

    private Database db;
    private DatabaseExecutionContext executionContext;

    @Inject
    public JavaApplicationDataBase(@NamedDatabase("baseplay") Database db, DatabaseExecutionContext executionContext) {
        this.db = db;
        this.executionContext = executionContext;
    }

文件config'application.conf':

# Default database configuration
db.default.driver=com.mysql.jdbc.Driver
db.default.url="jdbc:mysql://localhost/baseplay"
db.default.username=root
db.default.password="root"

和配置文件'build.sbt':

name := """play-java-forms-example"""

version := "2.6.x"

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

scalaVersion := "2.12.4"

crossScalaVersions := Seq("2.11.12", "2.12.4")

testOptions in Test := Seq(Tests.Argument(TestFrameworks.JUnit, "-a", "-v"))

libraryDependencies += guice

EclipseKeys.preTasks := Seq(compile in Compile, compile in Test) 

libraryDependencies += javaJdbc

libraryDependencies ++= Seq(
  cache,
  ws,
  specs2 % Test,
  "mysql" % "mysql-connector-java" % "5.1.41"
)

感谢。

1 个答案:

答案 0 :(得分:0)

您将需要将config db名称更改为要在@NamedDatabase(“ baseplay”)中注入的名称。因此,在这种情况下,您的配置将类似于:

# Default database configuration
db.baseplay.driver=com.mysql.jdbc.Driver
db.baseplay.url="jdbc:mysql://localhost/baseplay"
db.baseplay.username=root
db.baseplay.password="root"