我正在尝试将Play 2.4与MyBatis一起使用,但仍保留HikariCP连接池和基于Guice的新依赖注入。
尝试查看网页时出现以下错误:
CreationException: Unable to create injector, see the following errors:
1) No implementation for play.db.Database was bound.
但是它应该位于play.db.DBModule
内的play-jdbc_2.11-2.4.2.jar
内,对吗?
所以我强行添加到application.conf
(这不应该是必要的,因为它已经在Jar的reference.conf
添加了
play.modules.enabled += "play.db.DBModule"
这使错误更加严重:
play.api.PlayException: Cannot load module[Module [play.db.DBModule] cannot be instantiated.]
...snip...
Caused by: java.lang.ClassNotFoundException: play.db.DBModule
at java.net.URLClassLoader$1.run(URLClassLoader.java:372) ~[na:1.8.0_20]
at java.net.URLClassLoader$1.run(URLClassLoader.java:361) ~[na:1.8.0_20]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_20]
at java.net.URLClassLoader.findClass(URLClassLoader.java:360) ~[na:1.8.0_20]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_20]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_20]
at play.api.inject.Modules$$anonfun$locate$1.apply(Module.scala:105) ~[play_2.11-2.4.2.jar:2.4.2]
... 36 common frames omitted
活泉? OO 这清楚地表明事物不在类路径上(或者类加载器无法找到),对吧?但它应该是!
当我问activator
show fullClasspath
时,它会告诉我Attributed(/Users/<me>/.ivy2/cache/com.typesafe.play/play-jdbc_2.11/jars/play-jdbc_2.11-2.4.2.jar)
已包含在内。
可能会说谎。但即使要求lsof -p <PID>
告诉我该流程已声明该文件。
这是我的build.sbt
,任何人都有任何想法我可能做错了什么?
name := """MyBatisWithGuiceAndPlay"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
cache,
javaWs,
jdbc,
"com.google.guava" % "guava" % "18.0",
"org.mybatis" % "mybatis" % "3.3.0",
"org.mybatis" % "mybatis-guice" % "3.6",
"com.google.inject.extensions" % "guice-multibindings" % "4.0",
"org.freemarker" % "freemarker" % "2.3.23",
"org.webjars" % "yui-pure" % "0.5.0",
"org.webjars" % "jquery" % "2.1.4",
"org.webjars" % "select2" % "4.0.0-2",
"org.webjars" % "datatables" % "1.10.7",
"org.webjars" % "datatables-fixedheader" % "2.1.2-1"
)
答案 0 :(得分:2)
将jdbc
替换为javaJdbc
。 build.sbt
java依赖项以java
为前缀,并遵循play.*
包名称约定。 Scala依赖项驻留在play.api.*
包中。