gpt4 book ai didi

java - 使用 Play 框架配置数据库 mysql 时出错

转载 作者:行者123 更新时间:2023-11-29 17:57:22 25 4
gpt4 key购买 nike

我从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;
}

文件配置“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"
)

谢谢。

最佳答案

您需要将配置数据库名称更改为您想要在 @NamedDatabase("baseplay") 中注入(inject)的名称。所以在这种情况下你的配置将是这样的:

# 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"

关于java - 使用 Play 框架配置数据库 mysql 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48684397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com