Play Framework [2.4.x] - Module route name malfunction using `Assets is not a package member`

I am trying to provide modular specific routing that can be included in Play applications using the standard conf/routes route file as:

 -> /psmod1 com.escalesoft.psmod1.ctrl.Routes 

Compilation error received:

type Psmod1Assets is not included in the package com.escalesoft.psmod1.ctrl

To do this, I performed two steps, as indicated in the official documentation, in All classes and classes of controllers should be defined in the package controllers.admin

1. Define asset and controller classes in your own package

Define the asset class Psmod1Assets.scala as:

  package com.escalesoft.psmod1.ctrl

 import play.api.http.LazyHttpErrorHandler

  object   class Psmod1Assets extends controllers.AssetsBuilder (LazyHttpErrorHandler)

The above replacing an object by class resolves the issue

2. Split route file

Define the specific route file /conf/com.escalesoft.psmod1.ctrl.routes as:

 # Routes # Home page GET / com.escalesoft.psmod1.ctrl.Application.index # Map static resources from the /public folder to the /assets URL path GET /assets/*file com.escalesoft.psmod1.ctrl.Psmod1Assets.versioned(path="/public", file: Asset) 

If you like, you can check or clone the code of my small test project on github:

The project is configured to work using standard controllers.Assets . Go to the /conf/com.escalesoft.psmod1.ctrl.routes file (check it com.escalesoft.psmod1.ctrl.routes ) and replace the line controllers.Assets with the line com.escalesoft.psmod1.ctrl.Psmod1Assets to reproduce the compilation error .

I have already checked the following resources:

+1
source share
1 answer

Assets class The definition of Psmod1Assets.scala should be ... a class, not an object:

  package com.escalesoft.psmod1.ctrl

 import play.api.http.LazyHttpErrorHandler

 class Psmod1Assets extends controllers.AssetsBuilder (LazyHttpErrorHandler)

This refers to the InjectedRoutesGenerator parameter recommended in Play 2.4, which requires that built-in Assets be a class in order to take advantage of dependency injection. See Official ScalaRouting # Dependency-Injection Documentation

Keep in mind that the official documentation does not seem to be fully consistent with this change, but may still indicate object instead of class : https://www.playframework.com/documentation/2.4.x/SBTSubProjects#Assets-and-controller- classes-should-be-all-defined-in-the-controllers.admin-package

My little github test project mentioned in the problem description is not updated to work with custom com.escalesoft.psmod1.ctrl.Psmod1Assets

0
source

All Articles