简体   繁体   English

从另一个应用程序上下文注入bean?

[英]Inject a bean from another application context?

Is it possible to inject a bean from a web application that deploy in another server! 是否可以从部署在另一台服务器上的Web应用程序注入Bean!

I declare a scenario to myself, I have two web application that use spring framework and deploy separately in different application servers (one is TOMCAT and another one is WEBLOGIC),the first application has ServiceA and the second one has ServiceB, now I want to inject ServiceB in ServieA? 我向自己声明了一个方案,我有两个使用Spring框架并分别部署在不同应用程序服务器中的Web应用程序(一个是TOMCAT,另一个是WEBLOGIC),第一个应用程序具有ServiceA,第二个应用程序具有ServiceB,现在我想在ServieA中注入ServiceB?

I try to do this with RMI once an another one with JMS, now I am wondering that: 我尝试使用RMI一次使用JMS进行此操作,现在我很想知道:

Is it possible with another thing? 另一件事可能吗? Is there any active project about this scenario exist? 是否存在有关此方案的任何活动项目? How can share application context in spring framework, is it possible? 如何在Spring框架中共享应用程序上下文,这可能吗?

Thanks. 谢谢。

Bean is just an object in JVM. Bean只是JVM中的一个对象。 You certainly cannot use an object from one JVM in another JVM straightforward. 当然,您不能直接在另一个JVM中使用一个JVM中的对象。

But you can do 2 things: 但是您可以做两件事:

  1. Use proxies - some objects that will have the same interface but invoke somehow to the proper server as implementation. 使用代理-一些对象将具有相同的接口,但是以某种方式调用适当的服务器作为实现。
  2. Use service-oriented architecture (SOA). 使用面向服务的体系结构(SOA)。 Each server should have some limited set of beans that are responsible for their functionality. 每个服务器应具有负责其功能的一组有限的bean。 And all beans can interact with each other. 而且所有bean都可以互相影响。 Maybe OSGI is suitable for this. 也许OSGI适合于此。

Web services, JAX-RS is the simplest. Web服务中,JAX-RS是最简单的。 But JAX-WS provides you with the tools to automatically generate the client code. 但是JAX-WS为您提供了自动生成客户端代码的工具。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM