简体   繁体   English

方法不会覆盖任何内容Play Framework Scala

[英]method overrides nothing Play Framework Scala

I am implementing dependency injection in play Framework version 2.3.8 using guice. 我正在使用guice在play Framework版本2.3.8中实现依赖项注入。 Below is implementation of getControllerInstance of GlobalSettings trait. 以下是GlobalSettings特性的getControllerInstance的实现。

import com.google.inject.{ Guice, AbstractModule }
import play.api.GlobalSettings
import services._

object Global extends GlobalSettings {  
  val injector = Guice.createInjector(new AbstractModule {
    protected def configure() {
      bind(classOf[CategoryService]).to(classOf[CategoryServiceImpl])
    }
  })

  override def getControllerInstance[A](controllerClass: Class[A]): A = {
    injector.getInstance(controllerClass)
  }
}

When I compile the project, it gives Method overrides Nothing error. 当我编译项目时,它会给出“方法覆盖”,没有错误。 Below is the complete error description. 以下是完整的错误描述。

[error] /home/rajkumar/scalacb/PlayFrameworkCookbook/Handwritten /PFCChapter3Guice/app/Global.scala:14: method getControllerInstance overrides nothing
[error]   override def getControllerInstance[A](controllerClass: Class[A]): A = {
[error]                ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed

After removing the override in front of getControllerInstance, the compilation is successful. 删除getControllerInstance前面的替代后,编译成功。 After I ran the project, it throws different error. 运行项目后,它将引发不同的错误。

Below is the complete error trace. 下面是完整的错误跟踪。

! @6ol3cn5pi - Internal server error, for (GET) [/categories] ->

play.api.UnexpectedException: Unexpected   exception[ProvisionException:     Unable to provision, see the following   errors:

1) No implementation for services.CategoryService was bound.
while locating services.CategoryService
  for parameter 0 at controllers.CategoryController.<init>   (CategoryController.scala:7)
  while locating com.google.inject.Provider<controllers.CategoryController>
  for parameter 2 at router.Routes.<init>(Routes.scala:35)
  while locating router.Routes
  while locating play.api.inject.RoutesProvider
  while locating play.api.routing.Router 1 error]

Thanks in advance for your kind help. 在此先感谢您的帮助。

I think you should first double check that you are actually using Play 2.3.8, you can look in plugins.sbt to find out. 我认为您应该首先仔细检查您是否正在实际使用Play 2.3.8,可以在plugins.sbt中进行查找。

If it turns out that you are actually using Play 2.4, then I'm afraid it looks like the error message is correct in that getControllerInstance does not exist for you as this link shows https://www.playframework.com/documentation/2.4.x/api/java/play/GlobalSettings.html 如果事实证明您实际上在使用Play 2.4,那么恐怕该错误消息是正确的,因为该链接显示https://www.playframework.com/documentation/2.4,因为对您来说不存在getControllerInstance .X / API / JAVA /播放/ GlobalSettings.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM