7

I set up the application loader this way:

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]
  }
}

but my routes is custom, so it looks like:

the routes file:

-> /myApi/v1 v1.Routes
-> /MyHealthcheck HealthCheck.Routes

and my v1.Routes file:

GET    /getData    controllers.MyController.getData

so now when I compile the project I get this error:

Error: Cannot find a value of type: [v1.Routes] wire[Routes]

so im not sure how to fix this, does someone know how can I make the loader to work with this structure of routes?

JohnBigs
  • 2,691
  • 3
  • 31
  • 61
  • Your file should be named v1.routes with a lower case routes.Then @adamw 's answer works for me. – Saskia Dec 12 '18 at 16:18

2 Answers2

4

The answer by @marcospereira is correct, but maybe the code is slightly wrong.

The error is due to the routes file referencing v1.routes - this is compiled to a Routes class having a parameter of type v1.Routes.

You can see the generated code in target/scala-2.12/routes/main/router and /v1.

Hence to wire Router, you need a v1.Router instance. To create a v1.Router instance, you need first to wire it.

Here’s one way to fix the above example:

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]
}
adamw
  • 8,038
  • 4
  • 28
  • 32
1

You also need to wire the v1.Routes. See how it is done manually here:

https://www.playframework.com/documentation/2.6.x/ScalaCompileTimeDependencyInjection#Providing-a-router

This should work as you expect:

lazy val v1Routes = wire[v1.Routes]
lazy val wiredRouter = wire[Routes]

lazy val router = wiredRouter.withPrefix("/my-prefix")

ps.: didn't test it in a real project.

marcospereira
  • 12,045
  • 3
  • 46
  • 52
  • its not working :/ i get this error https://ibb.co/iHH99a and I did exactly as you wrote above (i know you didnt test it) and no success. also didnt really understand what to put in the Prefix.. – JohnBigs Jul 09 '17 at 11:24
  • also started a bounty :) – JohnBigs Jul 09 '17 at 11:26