首页 文章

无法导入类路由器 . 在Play 2.5上的ApplicationLoader中进行路由

提问于
浏览
2

我在使用Scala迁移到Play 2.5时遇到问题 . 我不得不开始使用DependencyInjection,在阅读了所有Play Framework 2.5迁移文档并完成所有相应的实现后,我遇到了一个奇怪的问题 . Play表示应该使用新的DependencyInjection模式自动生成类Routes,但是当我尝试在自定义ApplicationLoader中导入类时,编译器告诉我无法解析符号“router” . 以下是我的代码的一部分,希望你能帮助我,谢谢!

import controllers.Assets
import controllers.api.clients.ClientsController
import play.api.ApplicationLoader.Context
import play.api._
import play.api.libs.ws.ahc.AhcWSComponents
import router.Routes

class AppLoader extends ApplicationLoader {
  def load(context: Context) = {
    LoggerConfigurator(context.environment.classLoader).foreach {
      _.configure(context.environment)
    }

    new AppComponents(context).application
  }
}

class AppComponents(context: Context) extends BuiltInComponentsFromContext(context) with AhcWSComponents {

  lazy val clientsController: ClientsController = new ClientsController(wsClient)
  lazy val assets: Assets = new Assets(httpErrorHandler)

  lazy val router = new Routes(
    httpErrorHandler,
    clientsController,
    assets
  )
}

1 回答

  • 4

    检查以下内容:

    • 确保 build.sbt 包含 routesGenerator := InjectedRoutesGenerator

    • sbt 中执行 playCompileEverything 并在IDE中刷新项目

相关问题