gpt4 book ai didi

java - 神秘玩2.4注入(inject)异常

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:33:58 25 4
gpt4 key购买 nike

最近升级到 Play 2.4,我仍在学习所有的小怪癖等。我正在努力让我的索引页面正常工作,但我很难过,而且我知道这是我遗漏的一些小东西。这是错误

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):

还有我的配置信息(是的,mysql 的端口号是正确的)

应用程序.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.*"]

主 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);
}

内置.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)

插件.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")

您还有什么需要看的吗?

到目前为止,我已经尝试过重新导入依赖项,仔细检查以确保版本正确,再次查看文档,但到目前为止没有任何效果。我期待某个用户会得到所有的答案:)

最佳答案

Database connection configuration丢失了。

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"

关于java - 神秘玩2.4注入(inject)异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31244106/

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