Akka的官方文档上只有1.3.1版本有Spring Integration的部分,为啥到了2.2版本却不支持Spring集成了呢?R2有一段可参考:
The akka-spring module was not ported to the Akka 2.x series because it conflicts with the way actor systems work: with parental supervision only actors create other actors, which means that Spring—not being an actor—cannot create actors.
There is a new section in the documentation for the upcoming 2.2 release about how to use dependency injection while creating actors (see the docs). We are working on a more complete document describing the interplay between DI frameworks and Akka.
主要是说Akka 2.x必须通过actor来创建actor,否则Akka的supervision机制就不能发挥作用了。Nevertheless, Akka 2.x还是提供了和Dependency Injection配合的方式,见R3。准备测试一下这种官方的集成方式。
网上还看到一种集成方式,见R1,是写于May 2013的博客,但不知是针对什么Akka版本,但由于其内容的简单性,准备也测试一下。
<!-- AKKA System Setup -->
<bean id="myActorSystem" class="akka.actor.ActorSystem" factory-method="create" destroy-method="shutdown" scope="singleton">
<constructor-arg value="mySpingAkkaSystem"/>
</bean>
R1提供的这段配置可让Spring Container创建一个ActorSystem的实例,我们可以把这个bean注入到我们自己的bean里面,然后就可创建actor了。
等有空了对上面两种方式进行测试并报告结果。
UPDATE: R4 is the official means.
Reference 1: Integrating Akka with Spring & Java Web Applications. http://blog.nemccarthy.me/?p=295
Reference 3: http://doc.akka.io/docs/akka/2.2.0-RC1/java/untyped-actors.html#Creating_Actors_with_Factory_Methods
Reference 4: https://github.com/typesafehub/activator-akka-java-spring