简体   繁体   English

在Tomcat7下的Java Web应用程序项目中将Akka与Spring集成

[英]Integrate Akka with Spring in Java web application project under Tomcat7

I am interested in injecting Actors to beans, while the actors will be created by spring. 我对将Actor注入bean很感兴趣,而actor将在spring之前创建。 In addition, I am looking for ways to customize Akka configuration file path. 另外,我正在寻找自定义Akka配置文件路径的方法。

My project uses Java 7 and spring 3.2.5, akka version is 2.3.7. 我的项目使用Java 7和spring 3.2.5,akka版本是2.3.7。

I read some documents and guides that instruct to create a bean definition in my spring beans configuration file, as follows: 我阅读了一些文档和指南,它们指示在我的spring bean配置文件中创建bean定义,如下所示:

<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. spring根据默认配置成功创建了系统角色。 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: 我想根据/WEB-INF/application.conf文件初始化系统角色,我添加了-Dconfig.trace = loads系统属性以便调试配置加载,这是输出:

    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 从类加载器WebappClassLoader上下文中加载配置:/ MY-APP委托:错误的存储库: / WEB-INF / classes / ---------->父类加载器:org.apache.catalina.loader.StandardClassLoader@992f73但是没有名为application.conf的资源异常加载application.conf:java.io.IOException:在类路径中找不到资源:application.conf从类加载器WebappClassLoader上下文中加载配置:/ MY-APP委托:错误的存储库: / WEB-INF / classes / ---------->父类加载器:org.apache.catalina.loader.StandardClassLoader@992f73,但是没有名为application.json的异常资源加载application.json:java.io.IOException:资源在类路径中找不到:application.json从类加载器WebappClassLoader上下文中加载配置:/ MY-APP委托:错误的存储库: / WEB-INF / classes / ---------->父类加载器:org.apache。 catalina.loader.StandardClassLoader@992f73,但是没有资源称为application.properties异常加载 application.properties: java.io.IOException: resource not found on classpath: application.properties Did not find 'application' with any extension (.conf, .json, .properties); application.properties:java.io.IOException:在类路径中找不到资源:application.properties找不到具有任何扩展名(.conf,.json,.properties)的“ application”; 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 从URL jar加载配置:文件:/var/work/MY-APP/jakarta-tomcat/webapps/MY-APP/WEB-INF/lib/akka-actor_2.10-2.3.7.jar!/reference.conf来自类加载器WebappClassLoader上下文:/ MY-APP委托:错误的存储库: / WEB-INF / classes / ---------->父类加载器:org.apache.catalina.loader.StandardClassLoader@992f73

  • Is there a way to pass this path to system actor bean? 有没有办法将此路径传递给系统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"); 有一种方法可以在春季创建actor bean,而不是注入系统actor并使用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? 有关类似问题的许多答案都指向这篇文章: http : //blog.nemccarthy.me/? p=272,但是此页面处于脱机状态,有人知道那里写了什么吗?

Q1 Q1

You explicitly define where the conf file is stored, by default root classpath dir is scanned, WEB-INF/classes 您显式定义conf文件的存储位置,默认情况下会扫描根类路径dir WEB-INF/classes

-Dconfig.resource=/dev.conf

Q2 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. 按照activator-akka-java-spring中显示的模式 ,您可以完全使用该存储库中的代码,也可以使用自己的自定义逻辑对其进行自定义。 (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 您需要记住,扩展名需要使用ctx初始化

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

And then you can wrap it as you want, handling simple actor creation: 然后,您可以根据需要包装它,处理简单的actor创建:

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 Q3

Bounty ;) 赏金;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Git自动将Grails / Java Web应用程序部署到Tomcat7 - Automated deployment of Grails/Java web application to Tomcat7 from Git 如何在线托管使用jpa toplink,tomcat7 mysql和primefaces创建的Java Web动态项目 - How to host online a java web dynamic project created using jpa toplink, tomcat7 mysql and primefaces Tomcat7 / Java项目:找出起点,我的应用程序从哪里开始? - Tomcat7/Java Project: Finding out the starting point, where does my application starts? 在Tomcat7上安装应用程序 - Install Application on Tomcat7 将Web项目部署到Tomcat7后出现404错误 - Getting an 404 error after deploying web project to Tomcat7 ClassNotFoundException:IntelliJ IDEA在tomcat7上部署Maven Spring MVC Web项目时出现org.springframework.core.io.Resource - ClassNotFoundException: org.springframework.core.io.Resource when intellij idea deploy maven spring mvc web project on tomcat7 如何使用 Eclipse Indigo 在 Tomcat7 中部署 Web 应用程序? - How to deploy Web Application in Tomcat7 using Eclipse Indigo? Tomcat7无法部署Web应用程序CSRF令牌 - Tomcat7 failed to deploy a web application CSRF Token 在 Tomcat7 上部署后,Java Spring 应用程序无法运行 - Java Spring app can't run after deploy on Tomcat7 Tomcat7无法在我的Java Web应用程序中加载欢迎页面 - Tomcat7 not load welcome page in my Java Web app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM