我是Play框架的新手,无法弄清楚为什么我从Play 2.6文档here复制并粘贴的应用程序加载器类中遇到此错误,并对新版本进行了一些修改和光滑的进化的过程。
这是我的build.sbt中引用库的部分:
scalaVersion := "2.12.2"
libraryDependencies ++= Seq(evolutions, jdbc)
libraryDependencies ++= Seq(jdbc, ehcache , ws , specs2 % Test , guice )
libraryDependencies ++= Seq("com.typesafe.play" %% "play" % "2.6.11")
libraryDependencies += "com.typesafe.play" %% "play-slick" % "3.0.1"
libraryDependencies += "com.typesafe.play" %% "play-slick-evolutions" % "3.0.1"
libraryDependencies ++= Seq("mysql" % "mysql-connector-java" % "5.1.36")
这是我的application.conf
play.application.loader=AppComponents
这是我放在根目录中的AppComponents类
import play.api.ApplicationLoader.Context
import play.api.BuiltInComponentsFromContext
import play.api.db.{Database, DBComponents, HikariCPComponents}
import play.api.db.slick.evolutions.{SlickEvolutionsComponents}
import play.api.routing.Router
import play.filters.HttpFiltersComponents
class AppComponents(cntx: Context)
extends BuiltInComponentsFromContext(cntx)
with DBComponents
with SlickEvolutionsComponents
with HikariCPComponents
with HttpFiltersComponents
{
// this will actually run the database migrations on startup
applicationEvolutions
}
我已经检查了下载的play-slick-evolutions_2.12-3.0.1.jar jar,它确实有play.api.db.slick.evolutions。我还尝试过与Play 2.6文档中的代码完全相符的早期版本,但那里也不包含任何演变。
答案 0 :(得分:0)
首先,项目重建解决了初始错误,但是并没有解决Application Loader的问题。为了解决这个问题,我返回了Play 2.6文档,并将该类还原到他们提供的段,并删除了play-slick sbt条目,还原到文档中的条目。仍然存在问题,在找到另一个示例时,很明显我没有完整的课程。在这里:
import play.api.ApplicationLoader
import play.api.ApplicationLoader.Context
import play.api.BuiltInComponentsFromContext
import play.api.db.{Database, DBComponents, HikariCPComponents}
import play.api.db.evolutions.EvolutionsComponents
import play.api.routing.Router
import play.filters.HttpFiltersComponents
class MyApplicationLoader extends ApplicationLoader {
def load(context: Context) = {
new MyComponents(context).application
}
}
class MyComponents(cntx: Context)
extends BuiltInComponentsFromContext(cntx)
with DBComponents
with EvolutionsComponents
with HikariCPComponents
with HttpFiltersComponents
{
// this will actually run the database migrations on startup
lazy val router = Router.empty
applicationEvolutions
}
我也将application.conf设置调整为:
play.application.loader=MyApplicationLoader
请注意,我仍然需要添加路由,因为lazy val router = Route.empty会显示一个网页,显示:
找不到动作 对于请求“获取/”
已尝试按照以下顺序尝试以下路线: