使用JBoss和Spring在Java Web应用程序之间共享业务对象实例的最佳方式是什么? [英] What's the best way to share business object instances between Java web apps using JBoss and Spring?

查看:98
本文介绍了使用JBoss和Spring在Java Web应用程序之间共享业务对象实例的最佳方式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前有一个Web应用程序加载一个Spring应用程序上下文,它实例化一堆业务对象,DAO对象和Hibernate。我们希望与另一个Web应用程序共享此堆栈,以避免出现同一对象的多个实例。



我们研究了几种方法;使用JMX或JNDI或使用EJB3公开对象。

不同的方法都有他们的问题,我们正在寻找一种轻量级的方法。



有关如何解决这个问题的任何建议?

编辑:我收到了一些要求我详细阐述的意见,所以这里是:

我们想要解决的主要问题是我们只想要一个Hibernate实例。这是由于在运行多个使用相同数据源的客户端应用程序时,Hibernate的二级缓存失效导致的问题。另外,业务/ DAO / Hibernate堆栈也越来越大,所以不重复它就更有意义。

首先,我们试图研究业务层如何可能会暴露给其他Web应用程序,并且Spring以少量XML的价格提供JMX包装。但是,我们无法将JMX实体绑定到JNDI树,因此我们无法从Web应用程序中查找对象。

然后,我们尝试绑定业务层直接发送给JNDI。尽管Spring没有提供任何方法,但使用JNDITemplate绑定它们也是微不足道的。但是这导致了一些新问题:1)安全管理器拒绝访问RMI类加载器,所以一旦我们尝试调用JNDI资源上的方法,客户端就会失败。 2)一旦安全问题得到解决,JBoss抛出IllegalArgumentException:对象不是声明类的实例。有些阅读表明我们需要JNDI资源的存根实现,但这似乎很麻烦(也许Spring可以帮助我们?)

我们还没有看起来太过于EJB了,但在前两次尝试后,我想知道我们试图实现的是否可能。总结我们想要达到的目标:一个JBoss实例,几个Web应用程序在DAO层和Hibernate之上利用一堆业务对象。

>

祝好,

Nils

解决方案



我不能说Spring,但直接将您的业务逻辑转移使用会话Bean的EJB层。

应用程序组织非常简单。逻辑进入会话Bean,并且这些会话Bean作为具有ejb-jar.xml文件的Java EE工件捆绑在一个jar中(在EJB3中,这可能实际上是空的)。



然后将实体类绑定到单独的jar文件中。

接下来,您将构建每个Web应用程序到自己的WAR文件中。

最后,所有的jar和war都捆绑到一个Java EE EAR中,并附带关联的application.xml文件(同样,这可能会非常小,简单地枚举EAR中的罐子)。



这个EAR被批量部署到应用服务器。



每个WAR实际上是独立的 - 它们自己的会话,自己的上下文路径等等。但是它们共享EJB后端,所以你只有一个二级缓存。



您还使用本地引用和调用语义来与EJB交谈,因为它们位于同一台服务器中。在这里不需要远程调用。



我认为这很好地解决了您遇到的问题,并且在EJB 3的Java EE 5中它非常简单。 p>

另外,就我所知,你仍然可以在Spring的大部分工作中使用Spring,但我不是Spring的人,所以我不能说详细信息。


We currently have a web application loading a Spring application context which instantiates a stack of business objects, DAO objects and Hibernate. We would like to share this stack with another web application, to avoid having multiple instances of the same objects.

We have looked into several approaches; exposing the objects using JMX or JNDI, or using EJB3.

The different approaches all have their issues, and we are looking for a lightweight method.

Any suggestions on how to solve this?

Edit: I have received comments requesting me to elaborate a bit, so here goes:

The main problem we want to solve is that we want to have only one instance of Hibernate. This is due to problems with invalidation of Hibernate's 2nd level cache when running several client applications working with the same datasource. Also, the business/DAO/Hibernate stack is growing rather large, so not duplicating it just makes more sense.

First, we tried to look at how the business layer alone could be exposed to other web apps, and Spring offers JMX wrapping at the price of a tiny amount of XML. However, we were unable to bind the JMX entities to the JNDI tree, so we couldn't lookup the objects from the web apps.

Then we tried binding the business layer directly to JNDI. Although Spring didn't offer any method for this, using JNDITemplate to bind them was also trivial. But this led to several new problems: 1) Security manager denies access to RMI classloader, so the client failed once we tried to invoke methods on the JNDI resource. 2) Once the security issues were resolved, JBoss threw IllegalArgumentException: object is not an instance of declaring class. A bit of reading reveals that we need stub implementations for the JNDI resources, but this seems like a lot of hassle (perhaps Spring can help us?)

We haven't looked too much into EJB yet, but after the first two tries I'm wondering if what we're trying to achieve is at all possible.

To sum up what we're trying to achieve: One JBoss instance, several web apps utilizing one stack of business objects on top of DAO layer and Hibernate.

Best regards,

Nils

解决方案

Are the web applications deployed on the same server?

I can't speak for Spring, but it is straightforward to move your business logic in to the EJB tier using Session Beans.

The application organization is straight forward. The Logic goes in to Session Beans, and these Session Beans are bundled within a single jar as an Java EE artifact with a ejb-jar.xml file (in EJB3, this will likely be practically empty).

Then bundle you Entity classes in to a seperate jar file.

Next, you will build each web app in to their own WAR file.

Finally, all of the jars and the wars are bundled in to a Java EE EAR, with the associated application.xml file (again, this will likely be quite minimal, simply enumerating the jars in the EAR).

This EAR is deployed wholesale to the app server.

Each WAR is effectively independent -- their own sessions, there own context paths, etc. But they share the common EJB back end, so you have only a single 2nd level cache.

You also use local references and calling semantic to talk to the EJBs since they're in the same server. No need for remote calls here.

I think this solves quite well the issue you're having, and its is quite straightforward in Java EE 5 with EJB 3.

Also, you can still use Spring for much of your work, as I understand, but I'm not a Spring person so I can not speak to the details.

这篇关于使用JBoss和Spring在Java Web应用程序之间共享业务对象实例的最佳方式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆