akka创建actor时报错:IllegalArgumentException: no matching constructor found on class $iwC$$iwC$$iwC$$iwC$
在spark-shell中输入范例中的代码:
import akka.actor.Actor import akka.actor.Props import akka.event.Logging class MyActor extends Actor { val log = Logging(context.system, this) def receive = { case "test" ⇒ log.info("received test") case _ ⇒ log.info("received unknown message") } } val system = ActorSystem("MySystem") val myActor = system.actorOf(Props[MyActor], name = "myactor")
结果总是遇到如下错误:
百思不得其解!最后终于找到了原因:不能采用内嵌类作为actor类!!!!spark-shell里面的类会被认为是内嵌类,为了避免以上错误,需要单独写类文件。stackoverflow里面是这么解释的:
Take this example:
class A{ class B{} }
I can do
new A
, butnew B
will return an error. I have to do:val a = new A val b = new a.B
That's why akka failed to create this actor.