我这样设置应用程序加载器:
class MyProjectApplicationLoader extends ApplicationLoader { def load(context: Context): Application = new ApplicationComponents(context).application } class ApplicationComponents(context: Context) extends BuiltInComponentsFromContext(context) with QAControllerModule with play.filters.HttpFiltersComponents { // set up logger LoggerConfigurator(context.environment.classLoader).foreach { _.configure(context.environment,context.initialConfiguration,Map.empty) } lazy val router: Router = { // add the prefix string in local scope for the Routes constructor val prefix: String = "/" wire[Routes] } }
但我的路线是自定义的,所以它看起来像:
路线文件:
-> /myApi/v1 v1.Routes -> /MyHealthcheck HealthCheck.Routes
和我的v1.Routes文件:
GET /getData controllers.MyController.getData
所以现在当我编译项目时,我收到此错误:
Error: Cannot find a value of type: [v1.Routes]
wire[Routes]
所以我不知道如何解决这个问题,有人知道如何使加载程序与这种路由结构一起工作?
解决方法
@marcospereira的答案是正确的,但也许代码有点错误.
该错误是由路由文件引用v1.routes引起的 – 这被编译为具有类型为v1.Routes的参数的Routes类.
您可以在target / scala-2.12 / routes / main / router和/ v1中看到生成的代码.
因此,要连接路由器,您需要一个v1.Router实例.要创建v1.Router实例,首先需要连接它.
以下是修复上述示例的一种方法:
lazy val router: Router = { // add the prefix string in local scope for the Routes constructor val prefix: String = "/" val v1Routes = wire[v1.Routes] wire[Routes] }