1

我正在使用 MacWire DI 框架,但出现此错误。

Found multiple values of type [play.api.mvc.DefaultActionBuilder]: [List(defaultActionBuilder, Action)]
[error]   override lazy val controllerComponents: DefaultControllerComponents = wire[DefaultControllerComponents]

我的应用程序加载器是这样的:

class AppApplicationLoader extends ApplicationLoader {
  def load(context: Context) = {
    LoggerConfigurator(context.environment.classLoader).foreach { cfg =>
      cfg.configure(context.environment)
    }
    new AppComponents(context).application
  }
}

 class AppComponents(context: Context) extends
      BuiltInComponentsFromContext(context) with AhcWSComponents
      with AssetsComponents with HttpFiltersComponents
      with EvolutionsComponents with DBComponents  with HikariCPComponents  with EhCacheComponents {

      override lazy val controllerComponents: DefaultControllerComponents = wire[DefaultControllerComponents]

在对代码进行少量修改后,我遇到了一些其他类似的错误。如何遵循 DI 依赖项来追踪这些错误?

4

1 回答 1

2

我自己刚遇到这个,似乎是由于这个提交,它作为一个反向端口包含在 Play 2.6.3 中:

https://github.com/playframework/playframework/pull/7676/files/809cd1e880b01d45e95d41e65f20bfa984d1e122#r138400765

...因此使用 Play 2.6.2 编译的代码在 Play 2.6.3 中失败。

解决方法:

  • 恢复到 Play 2.6.2,或者...
  • ...手动指定您的创建DefaultControllerComponents- 即不要将 MacWire 用于该特定构造函数

这不是那么漂亮,但它适用于 Play 2.6.3:

val defaultControllerComponents = new DefaultControllerComponents(
  defaultActionBuilder,
  playBodyParsers,
  messagesApi,
  langs,
  fileMimeTypes,
  executionContext
)
于 2017-09-12T16:42:57.200 回答