将多个WAR重新打包到一个EAR中(Repackage several WARs into one EAR)

编程入门 行业动态 更新时间:2024-10-28 12:27:57
多个WAR重新打包到一个EAR中(Repackage several WARs into one EAR)

我正在开发一个项目,该项目有几个使用Maven构建并部署在Java EE中的webapps(WAR)。

这些WAR共享几个常见的业务JARS(比如一个包含从hibernate加载的域对象)和其他框架JAR,如Spring和Hibernate。

他们使用Spring MVC,Application Context加载Hibernate。 由于每个WAR在servlet容器中都有自己的Classpath,因此不共享Hibernate缓存(EHcache)。

我想要的是在不同的WAR之间共享缓存以及hibernate会话工厂bean(以及其他常见的bean)。 我认为这可以通过在EAR中重新打包这些WAR来实现,然后我必须使用这些commons bean创建一个spring配置XML,并且在WAR的Spring XML中使用类似于我读过的SingletonBeanFactoryLocator。

我在这里问的是,是否有一种简单的方法可以做到这一点,最大限度地减少对WAR的POM的更改

注意:我熟悉WAR,tomcat和servlet,但对EAR并不熟悉。

提前致谢。

I'm working on a project that have several webapps (WARs) built with Maven and deployed in a Java EE.

These WARs share several common business JARS (like one containing domain objects which are loaded from hibernate) and other framework JARs like Spring and Hibernate.

They use Spring MVC, and the Application Context loads Hibernate. As each WAR has its own Classpath in the servlet container, the Hibernate cache (EHcache) is not shared.

What I'd like is to share the cache and also the hibernate session factory bean (as well as other common beans) betweeen the different WARs. I think this is possible by repackaging those WARs inside an EAR and then I'd have to make a spring configuration XML using those commons beans and in the WAR's Spring XML use something like SingletonBeanFactoryLocator from what I've read.

What I'm asking here is if there is a simple way to do this, minimizing changes to the WARs' POMs

Note: I'm familiar with WARs, tomcat and servlets, but not so much with EARs.

Thanks in advance.

最满意答案

嗯......大多数Java EE容器都使用隔离的类加载器用于WAR,即使在EAR中也是如此(即使Java EE规范没有强制要求在单个EAR的模块之间进行类加载隔离),所以我不会期望从EAR包装中获得太多,特别是如果您希望您的应用程序保持可移植性(即,如果您不想依赖任何特定于应用程序服务器的行为)。

现在,如果真的有意义的是在多个应用程序之间共享会话工厂和二级缓存,可以考虑将它们合并到一个WAR中。 这将是IMO最简单的方式。 但我很想问他们为什么分开呢? 当应用程序是独立的时,它们大部分时间都是单独的治理,我不知道在这种情况下将它们一起部署在一起是否是个好主意。

如果不能合并WAR,请告诉我们您正在使用哪个容器。

Hmmm... Most Java EE containers use isolated classloaders for WARs, even in an EAR (even if the Java EE spec does not mandate class loading isolation among modules of a single EAR) so I wouldn't expect to much from an EAR packaging, especially if you want your application to remain portable (i.e. if you don't want to rely on any app server specific behavior).

Now, if really it makes sense to share your session factory and your 2nd level cache between several applications, maybe consider merging them in a single WAR. That would be the easiest way IMO. But I'd be tempted to ask why are they separate then? When applications are separate, they have most of time separate governance and I don't know if deploying them together would be a good idea in such case.

And if merging the WARs is not an option, please tell us which container you are using.

更多推荐

本文发布于:2023-08-05 15:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1434722.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   WAR   EAR   Repackage   WARs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!