如何防止使用guice模块?

时间:2018-11-22 12:39:43

标签: playframework guice

如何防止Guice在测试中配置此模块?

class SnsModule extends AbstractModule {
  override def configure(): Unit = {
    val snsClient: AmazonSNSAsyncClient = AmazonSNSAsyncClientBuilder.standard().build().asInstanceOf[AmazonSNSAsyncClient]
    bind(classOf[AmazonSNSAsyncClient]).toInstance(snsClient)
  }
}

我尝试覆盖该模块:

  private val snsModule = new AbstractModule{
    override def configure(): Unit = {
      val snsClient: AmazonSNSAsyncClient = mock[AmazonSNSAsyncClient]
      bind(classOf[AmazonSNSAsyncClient]).toInstance(snsClient)
    }
  }

  override implicit lazy val app: Application = GuiceApplicationBuilder().overrides(new TestJwkModule(),  snsModule).build()

但是仍然调用configure()中的SnsModule,这是一个问题,因为在我的测试环境中,AmazonSNSAsyncClientBuilder引发了异常。

1 个答案:

答案 0 :(得分:1)

disable阻止加载模块,例如:

override implicit lazy val app: Application = GuiceApplicationBuilder().
   disable(classOf[SnsModule])
   overrides(snsModule).build()