playframework - Scala play Guice injection -
i'm using scala play 2.5 , have following error while trying inject object in 1 of controllers. i'm using default injection framework given play guice.
provisionexception: unable provision, see following errors: 1) no implementation services.myservice bound. while locating services.myservice parameter 0 @ controllers.mycontroller.<init>(mycontroller.scala:12) while locating controllers.mycontroller parameter 3 @ router.routes.<init>(routes.scala:55) while locating router.routes while locating play.api.inject.routesprovider while locating play.api.routing.router parameter 0 @ play.api.http.javacompatiblehttprequesthandler.<init>(httprequesthandler.scala:200) while locating play.api.http.javacompatiblehttprequesthandler while locating play.api.http.httprequesthandler parameter 4 @ play.api.defaultapplication.<init>(application.scala:221) @ play.api.defaultapplication.class(application.scala:221) while locating play.api.defaultapplication while locating play.api.application
here controller:
package controllers import services.myservice class mycontroller @inject()(myservice: myservice, val messagesapi: messagesapi) extends controller i18nsupport { def somefunctionthatusesmyservice(url: string) = action {} }
here service inject:
package services import javax.inject._ trait myservice { def op(param1: string, param2: string): boolean } @singleton class basicmyservice extends myservice { override def op(param1: string, param2: string): boolean = true }
that how i'm using it:
@singleton class homecontroller @inject() extends controller { /** * create action render html page welcome message. * configuration in `routes` file means method * called when application receives `get` request * path of `/`. */ def index = action { //ok(views.html.index("your new application ready.")) redirect(routes.mycontroller.somefunctionthatusesmyservice(some(routes.othercontroller.welcomepage().url))) } }
you should add implementedby
annotation service trait
package services import javax.inject._ @implementedby(classof[basicmyservice]) trait myservice { def op(param1: string, param2: string): boolean } @singleton class basicmyservice extends myservice { override def op(param1: string, param2: string): boolean = true }
Comments
Post a Comment