gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 00:54:02 24 4
gpt4 key购买 nike

我在使用 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. 确保您的 build.sbt 包含 routesGenerator := InjectedRoutesGenerator

  2. sbt 中执行 playCompileEverything 并在您的 IDE 中刷新您的项目

关于scala - 无法在 Play 2.5 的 ApplicationLoader 中导入类 router.Routes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37333140/

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