我正在将Spray用于REST端点。如何获得ActorSystem
特质中现有的特征?
我不想在特征中创建新的ActorSystem
(如果可能的话),而是重用现有的ActorSystem
。我正在使用此Redis客户端库。
trait MySprayService extends HttpService with Json4sSupport {
//the following line requires an implicit ActorSystem
val redis = RedisClient(ip,port)
....
....
val simpleRoute = path("simple" / "route") {
get {
complete {
//use Redis here
}
}
}
}
您可以创建返回ActorSystem的抽象方法,然后在将扩展此特性的类中提供实现。
trait MySprayService extends HttpService with Json4sSupport {
implicit def as: ActorSystem
//the following line requires an implicit ActorSystem
val redis = RedisClient(ip,port)
....
....
val simpleRoute = path("simple" / "route") {
get {
complete {
//use Redis here
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句