Scala,ClassTag和Guice:注入构造函数时出错,java.lang.StackOverflowError

时间:2017-10-31 22:30:01

标签: scala reflection playframework guice classtag

在我的Play 2应用程序中,我需要在类中创建一个由Guice实例化的类标记(作为一个热切的单例;这是一个要求)。

case class UserCreated(id: Long, userName: String) extends ApplicationEvent

@Singleton
class AccountRoleUpdater @Inject()
    (accountRepository: AccountRepository)
    (implicit val actorSystem: ActorSystem, ec: ExecutionContext) {

    implicit def ct: ClassTag[UserCreated] = classTag[UserCreated]

    // THIS LINE CAUSES ERROR       
    val cls = ct.runtimeClass.asInstanceOf[Class[UserCreated]]     
}

这是Guice绑定:

class Module extends AbstractModule with AkkaGuiceSupport {
    bind(classOf[account.eventlistener.AccountRoleUpdater]).asEagerSingleton()
}

当应用程序启动时,我遇到以下异常:

  

CreationException:无法创建注入器,请参阅以下错误:

     

1)注入构造函数时出错,java.lang.StackOverflowError at   。account.eventlistener.AccountRoleUpdater(AccountRoleUpdater.scala:45)   在Module.configure(Module.scala:64)(通过模块:   com.google.inject.util.Modules $ OverrideModule - >模块)同时   找到account.eventlistener.AccountRoleUpdater

     

1错误]在   play.core.server.DevServerStart $$匿名$ 1.reload(DevServerStart.scala:186)     在   play.core.server.DevServerStart $$匿名$ 1.get(DevServerStart.scala:124)     在   play.core.server.AkkaHttpServer.modelConversion(AkkaHttpServer.scala:183)     在   play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:189)     在   。play.core.server.AkkaHttpServer $ $ anonfun $ createServerBinding 3(AkkaHttpServer.scala:106)     at akka.stream.impl.fusing.MapAsync $$ anon $ 23.onPush(Ops.scala:1172)     在   akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:499)     在   akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:462)     在   akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:368)     在   akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:571)   原因:com.google.inject.CreationException:无法创建   注入器,请参阅以下错误:

     

1)注入构造函数时出错,java.lang.StackOverflowError at   。account.eventlistener.AccountRoleUpdater(AccountRoleUpdater.scala:45)   在Module.configure(Module.scala:64)(通过模块:   com.google.inject.util.Modules $ OverrideModule - >模块)同时   找到account.eventlistener.AccountRoleUpdater

     

1错误   com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:470)     在   com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:184)     在   com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)     在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)     在   play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:137)     在   play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)     在   play.core.server.DevServerStart $$匿名$ $ 1 $ anonfun重装$ 3(DevServerStart.scala:174)     at play.utils.Threads $ .withContextClassLoader(Threads.scala:21)   引起:java.lang.StackOverflowError:null at   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)     在   account.eventlistener.AccountRoleUpdater.ct(AccountRoleUpdater.scala:21)

这似乎是一个周期性的参考。

0 个答案:

没有答案