Guice unable to create injector

Hi all!

When starting up a lagom service i get the following exception when i invoke runAll:

com.google.inject.CreationException: Unable to create injector, see the following errors:

  1. A binding to com.lightbend.lagom.internal.javadsl.server.ResolvedServices was already configured at com.lightbend.lagom.javadsl.server.ServiceGuiceSupport.bindServices(ServiceGu
    iceSupport.java:106) (via modules: com.google.inject.util.Modules$OverrideModule -> biz.demo.m2m.sub.impl.Module).
    at com.lightbend.lagom.javadsl.server.ServiceGuiceSupport.bindServices(ServiceGuiceSupport.java:106) (via modules: com.google.inject.util.Modules$OverrideModule -> biz.demo.m2m.su
    b.impl.Module)

  2. A binding to com.lightbend.lagom.javadsl.api.ServiceInfo was already configured at com.lightbend.lagom.javadsl.server.ServiceGuiceSupport.bindServices(ServiceGuiceSupport.java:8

  3. (via modules: com.google.inject.util.Modules$OverrideModule -> biz.demo.m2m.sub.impl.Module).
    at com.lightbend.lagom.javadsl.server.ServiceGuiceSupport.bindServices(ServiceGuiceSupport.java:89) (via modules: com.google.inject.util.Modules$OverrideModule -> biz.demo.m2m.sub
    .impl.Module)

2 errors
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:155)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:107)
at com.google.inject.Guice.createInjector(Guice.java:99)
at com.google.inject.Guice.createInjector(Guice.java:84)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:185)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:137)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.LagomReloadableDevServerStart$$anon$1.$anonfun$get$5(LagomReloadableDevServerStart.scala:176)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.core.server.LagomReloadableDevServerStart$$anon$1.$anonfun$get$3(LagomReloadableDevServerStart.scala:173)
at scala.Option.map(Option.scala:146)
at play.core.server.LagomReloadableDevServerStart$$anon$1.$anonfun$get$2(LagomReloadableDevServerStart.scala:149)
at scala.util.Success.flatMap(Try.scala:247)
at play.core.server.LagomReloadableDevServerStart$$anon$1.$anonfun$get$1(LagomReloadableDevServerStart.scala:147)
at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:655)
at scala.util.Success.$anonfun$map$1(Try.scala:251)
at scala.util.Success.map(Try.scala:209)
at scala.concurrent.Future.$anonfun$map$1(Future.scala:289)
at scala.concurrent.impl.Promise.liftedTree1$1(Promise.scala:29)
at scala.concurrent.impl.Promise.$anonfun$transform$1(Promise.scala:29)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

Stacktrace caused by project subscription-impl (filesystem path to project is C:\Users\micm\IdeaProjects\m2m\subscription-impl).
Hint: Maybe you have forgot to enable your service Module class via play.modules.enabled? (check in your project’s application.conf)

The content of the Module is:

public class Module extends AbstractModule implements ServiceGuiceSupport {

private final Environment environment;
private final Config config;

public Module(Environment environment, Config config) {
    this.environment = environment;
    this.config = config;
}

@Override
protected void configure() {
    bindClient(OrgService.class);
    bindClient(DevAppMapperService.class);

    bind(MappingUpdater.class).asEagerSingleton();
    bindService(SubscriptionService.class, SubscriptionServiceImpl.class);
    bindService(SubscriptionTemplateService.class, SubscriptionTemplateServiceImpl.class);

    if (environment.isProd()) {
        bind(ServiceLocator.class).to(ConfigurationServiceLocator.class);
    }
}

}

… and the entries in build.sbt are:

lazy val subscription-api = (project in file(“subscription-api”))
.settings(common: _*)
.settings(
libraryDependencies ++= Seq(
lagomJavadslApi,
lagomJavadslJackson,
lombok
)
)
.dependsOn(tools)

lazy val subscription-impl = (project in file(“subscription-impl”))
.enablePlugins(LagomJava, SbtReactiveAppPlugin)
.settings(common: _)
.settings(
libraryDependencies ++= Seq(
lagomJavadslPersistenceCassandra,
lagomJavadslKafkaBroker,
lagomJavadslTestKit
)
)
.settings(lagomForkedTestSettings: _
)
.dependsOn(security,organization-api,subscription-api,devappmapper-api)

I’ve really no clue what i can do to find the reason of this exception…

Any ideas?

greetings,
Michael

Hi @mm,

you can’t invoke bindService twice. You should merge the two descriptors into a single one.

Cheers,

Oh - didn’t now that. Thank you!