无法在 Play 2.5 上的 ApplicationLoader 中导入类 router.Routes

2 dependency-injection scala playframework

我在使用 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
  )
}
Run Code Online (Sandbox Code Playgroud)

EEC*_*LOR 6

检查以下内容:

  1. 确保您build.sbt包含routesGenerator := InjectedRoutesGenerator

  2. 执行playCompileEverythingsbt,并刷新您的项目在IDE