【发布时间】:2015-12-16 15:47:06
【问题描述】:
如何测试依赖注入创建的actor?在我的应用程序中,我可以通过命名注入获得 ActorRef:
public MyClass {
@Inject
@Named("ping")
ActorRef mPingRef;
}
如何在我的测试中获得此参考?
这是我的演员:
public class PingActor extends UntypedActor {
@Inject
public PingActor(Configuration configuration) {
... // Use config
}
@Override
public void onReceive(Object message) throws Exception {
if (message instanceof Ping) {
getSender().tell(new Pong(), getSelf());
}
}
public static class Ping {}
public static class Pong {}
}
我已经用我自己的模块配置了我的应用程序:
public class MyModule extends AbstractModule implements AkkaGuiceSupport {
private final Configuration mConfig;
public MyModule(Environment environment, Configuration configuration){
this.mConfig = configuration;
}
@Override
protected void configure() {
bindActor(PingActor.class, "ping");
}
}
模块在application.conf中启用:
play.modules.enabled += "com.my.package.MyModule"
【问题讨论】:
标签: playframework akka guice playframework-2.4