GuiceApplicationLoader 配置错误 [英] GuiceApplicationLoader configuration error

查看:116
本文介绍了GuiceApplicationLoader 配置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在尝试使用如下所示的内容来实现编译时 DI:

So, I'm trying to implement compile time DI with something that looks like this:

package modules

class MyModule extends AbstractModule {
  def configure() {
    bind(classOf[MyT]).to(classOf[MyTImpl])
  }
}

class MyApplicationLoader extends GuiceApplicationLoader {
  override protected def builder(context: ApplicationLoader.Context): GuiceApplicationBuilder = {
  initialBuilder
    .in(context.environment)
    .loadConfig(context.initialConfiguration)
    .overrides(overrides(context): _*)
    .load(new MyModule)
  }
}

application.conf 包括一行:

application.conf includes a line:

play.application.loader = "modules.MyApplicationLoader"

但是,当我尝试启动应用程序时,出现错误:

However, when I try to spin up the application, I get an error:

ConfigurationException: Guice configuration errors:

1) No implementation for play.api.Application was bound.
  while locating play.api.Application

1 error

No source available, here is the exception stack trace:
->com.google.inject.ConfigurationException: Guice configuration errors:

1) No implementation for play.api.Application was bound.
  while locating play.api.Application

1 error
     com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1042)
     com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1001)
     com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
....

不明白为什么这不起作用,因为我见过的所有示例都没有涉及更多.我忽略了什么?

Don't understand why this isn't working, as none of the examples I've seen for this do anything more involved. What am I overlooking?

推荐答案

Use bindings 而不是 load:

class MyApplicationLoader extends GuiceApplicationLoader {
  override protected def builder(context: ApplicationLoader.Context): GuiceApplicationBuilder = {
  initialBuilder
    .in(context.environment)
    .loadConfig(context.initialConfiguration)
    .overrides(overrides(context): _*)
    .bindings(new MyModule)
  }
}

这篇关于GuiceApplicationLoader 配置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆