将多个 WAR 重新打包到一个 EAR 中
我正在开发一个项目,该项目有多个使用 Maven 构建并部署在 Java EE 中的 Web 应用程序 (WAR)。
这些 WAR 共享几个常见的业务 JAR(例如包含从 hibernate 加载的域对象的 JAR)以及其他框架 JAR(例如 Spring 和 Hibernate)。
他们使用 Spring MVC,应用程序上下文加载 Hibernate。由于每个 WAR 在 servlet 容器中都有自己的 Classpath,因此 Hibernate 缓存 (EHcache) 不是共享的。
我想要的是在不同的 WAR 之间共享缓存以及 hibernate 会话工厂 bean(以及其他常见 bean)。我认为这可以通过将这些 WAR 重新打包到 EAR 中来实现,然后我必须使用这些公共 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嗯...大多数 Java EE 容器都使用隔离的类加载器进行 WAR,即使是在 EAR 中(即使 Java EE 规范不要求单个 EAR 模块之间的类加载隔离),所以我不会对 EAR 打包抱有很大期望,特别是如果您希望应用程序保持可移植性(即,如果您不想依赖任何应用程序服务器特定行为)。
现在,如果在多个应用程序之间共享会话工厂和二级缓存确实有意义,则可以考虑将它们合并到单个 WAR 中。在我看来,这将是最简单的方法。但我很想问为什么它们是分开的?当应用程序是独立的时,它们大多数时候都有单独的治理,我不知道在这种情况下将它们部署在一起是否是一个好主意。
如果无法合并 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.
您是否考虑过使用一致的集群 L2 缓存?如果您使用多个应用程序服务器,您可能会看到更多好处,因为它们都将共享相同的一致缓存
Have you considered making use of a coherent clustered L2 cache? If you're using multiple app servers you might see more benefit then as they would all be sharing the same coherent cache
在多战争 Spring 应用程序中使用共享父应用程序上下文
http://blog.springsource.org/2007/06/11/using-a-shared-parent-application-context-在-multi-war-spring-application/
Using a shared parent application context in a multi-war spring application
http://blog.springsource.org/2007/06/11/using-a-shared-parent-application-context-in-a-multi-war-spring-application/