【问题标题】:MacWire: Found multiple values of typeMacWire:找到多个类型的值
【发布时间】:2018-02-15 22:29:11
【问题描述】:

我正在使用 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 依赖项来追踪这些错误?

【问题讨论】:

    标签: scala playframework-2.0 playframework-2.6 macwire


    【解决方案1】:

    我自己刚遇到这个,似乎是由于这个提交,它作为一个反向移植包含在 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
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-13
      • 2022-08-19
      • 2019-04-03
      • 1970-01-01
      • 1970-01-01
      • 2018-02-28
      • 2021-12-04
      • 2021-09-18
      相关资源
      最近更新 更多