0
votes

I am interested in injecting Actors to beans, while the actors will be created by spring. In addition, I am looking for ways to customize Akka configuration file path.

My project uses Java 7 and spring 3.2.5, akka version is 2.3.7.

I read some documents and guides that instruct to create a bean definition in my spring beans configuration file, as follows:

<bean id="system-actor" class="akka.actor.ActorSystem" factory-method="create" destroy-method="shutdown" scope="singleton">
    <constructor-arg value="MyApp" />
</bean>

The system actor created by spring successfully according to default configuration. Questions:

  • I want to initialize the system actor according to /WEB-INF/application.conf file, I added the -Dconfig.trace=loads system property in order to debug configuration loading, this is the output:

    Loading config from class loader WebappClassLoader context: /MY-APP delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@992f73 but there were no resources called application.conf exception loading application.conf: java.io.IOException: resource not found on classpath: application.conf Loading config from class loader WebappClassLoader context: /MY-APP delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@992f73 but there were no resources called application.json exception loading application.json: java.io.IOException: resource not found on classpath: application.json Loading config from class loader WebappClassLoader context: /MY-APP delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@992f73 but there were no resources called application.properties exception loading application.properties: java.io.IOException: resource not found on classpath: application.properties Did not find 'application' with any extension (.conf, .json, .properties); but 'application' is allowed to be missing. Exceptions from load attempts should have been logged above. Loading config from URL jar:file:/var/work/MY-APP/jakarta-tomcat/webapps/MY-APP/WEB-INF/lib/akka-actor_2.10-2.3.7.jar!/reference.conf from class loader WebappClassLoader context: /MY-APP delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@992f73

  • Is there a way to pass this path to system actor bean?

  • There is a way to create actor beans in spring instead of injecting the system actor and using system.actorOf(Props.create(MyActor.class), "name");? Detailed examples will be helpful.

  • Many answers to simillar issues point to this article: http://blog.nemccarthy.me/?p=272 but this page is offline, someone knows what's written there?
1

1 Answers

0
votes

Q1

You explicitly define where the conf file is stored, by default root classpath dir is scanned, WEB-INF/classes

-Dconfig.resource=/dev.conf

Q2

Follow the pattern presented in the activator-akka-java-spring, you can use exactly the code from that repository or customize it using your own custom logic. (Sooner or later you'll uderstand why you need to customize it )

You need to keep in mind that extension needs to be initialized with ctx

SpringExtProvider.get(system).initialize(applicationContext);

And then you can wrap it as you want, handling simple actor creation:

ActorRef counter = system.actorOf(
      SpringExtProvider.get(system).props("quartz"), "quartz");

or even more complex cases with singleton:

ActorRef quartzCoordinator = getContext().actorOf(ClusterSingletonManager.defaultProps(SpringExtProviderget(getContext().system()).props("quartz"), "quartz",
                PoisonPill.getInstance(), "core"), "coordinator");

Q3

Bounty ;)