1
votes

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

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

Compilation error obtained:

type Psmod1Assets is not a member of package com.escalesoft.psmod1.ctrl

To accomplish this I followed two steps as instructed in the official documentation at Assets and controller classes should be all defined in the controllers.admin package

1. Define Assets and controller classes in their own package

Define Assets class Psmod1Assets.scala as:

package com.escalesoft.psmod1.ctrl

import play.api.http.LazyHttpErrorHandler

object class Psmod1Assets extends controllers.AssetsBuilder(LazyHttpErrorHandler)

The above object definition replacement by class fixes the problem

2. Splitting the route file

Define module 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 /conf/com.escalesoft.psmod1.ctrl.routes file (check it at com.escalesoft.psmod1.ctrl.routes) and replace line with controllers.Assets by line with com.escalesoft.psmod1.ctrl.Psmod1Assets to reproduce the compilation error.

I already checked the following resources:

1
object instead of class in Psmod1Assets definition was the culprit! As pointed out by a comment of akauppi in stackoverflow.com/questions/32595309/…Patrick Refondini

1 Answers

0
votes

Assets class Psmod1Assets.scala definition must be ... a class not an object:

package com.escalesoft.psmod1.ctrl

import play.api.http.LazyHttpErrorHandler

class Psmod1Assets extends controllers.AssetsBuilder(LazyHttpErrorHandler)

This relates to the Play 2.4 recommended InjectedRoutesGenerator setting which requires the built Assets to be a class to benefit from dependency injection. See official documentation at ScalaRouting#Dependency-Injection

Be aware that the official documentation seems not to be completely consistent with this change yet an may still state 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 small test project on github mentionned in the problem description is not updated to work with the custom com.escalesoft.psmod1.ctrl.Psmod1Assets