我可以在Play Framework中获取默认actor系统的实例

问题描述 投票:0回答:1

默认播放框架应用程序具有异步控制器。我需要qazxsw poi。

ActorSystem

我正在创建一个需要编译时依赖注入的代码。我想我必须创建我的应用程序的所有控制器的实例,并将其传递给class AsyncController @Inject()(cc: ControllerComponents, actorSystem: ActorSystem)(implicit exec: ExecutionContext) extends AbstractController(cc) {

Routes

我的问题是我在创建AsyncController实例时不知道要传递什么作为lazy val router = new Routes(httpErrorHandler, homeController,userWSRoutes, countController,asyncController, assets)

ActorSystem

我试过注入(也试过隐式)参数,但它没有用

lazy val asyncController = new controllers.AsyncController(controllerComponents, system) //what should be system.

我收到以下错误

class AppLoader @Inject()(system: ActorSystem) extends ApplicationLoader {
  override def load(context: ApplicationLoader.Context): Application =
    new AppComponents(system, context).application
}

class AppComponents (system: ActorSystem, context: Context) extends BuiltInComponentsFromContext(context)
  with CassandraRepositoryComponents
  with HttpFiltersComponents
  with controllers.AssetsComponents{
...
lazy val asyncController = new controllers.AsyncController(controllerComponents, system) //doesn't work.
}
playframework-2.6
1个回答
0
投票

! @777ipfa31 - Internal server error, for (GET) [/] -> play.api.UnexpectedException: Unexpected exception[InstantiationException: AppLoader] at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:186) at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124) at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:189) at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:106) at akka.stream.impl.fusing.MapAsync$$anon$25.onPush(Ops.scala:1194) at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:519) at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:482) at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:378) at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:585) at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:469) Caused by: java.lang.InstantiationException: AppLoader at java.lang.Class.newInstance(Class.java:427) at play.api.ApplicationLoader$.apply(ApplicationLoader.scala:79) at play.core.server.DevServerStart$$anon$1.$anonfun$reload$3(DevServerStart.scala:173) at play.utils.Threads$.withContextClassLoader(Threads.scala:21) at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:171) at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124) at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:189) at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:106) at akka.stream.impl.fusing.MapAsync$$anon$25.onPush(Ops.scala:1194) at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:519) Caused by: java.lang.NoSuchMethodException: AppLoader.<init>() at java.lang.Class.getConstructor0(Class.java:3082) at java.lang.Class.newInstance(Class.java:412) at play.api.ApplicationLoader$.apply(ApplicationLoader.scala:79) at play.core.server.DevServerStart$$anon$1.$anonfun$reload$3(DevServerStart.scala:173) at play.utils.Threads$.withContextClassLoader(Threads.scala:21) at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:171) at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:124) at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:189) at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:106) at akka.stream.impl.fusing.MapAsync$$anon$25.onPush(Ops.scala:1194) [error] application - 在其变量BuiltInComponentsFromContext中引用了Actor系统。

actorSystem

lazy val asyncController = new controllers.AsyncController(controllerComponents, actorSystem)

© www.soinside.com 2019 - 2024. All rights reserved.