我在处理具有多个 EE 可部署项的项目时发现了一个非常复杂的问题。该问题似乎是 EJB3.1 TimerService 的 Hibernate 依赖项和类加载器隔离不足共同造成的。
从库存 AS 6 CR1 构建开始,我部署了 WAR。此 WAR 包含 Hibernate jar。
然后,我在 JAR 中部署 EJB(技术上是 MDB)。当我这样做时,JBoss 然后启动 TimerService,以提供完整的 EJB3.1 支持。 TimerService 依赖于 Hibernate。然后 JBoss 罢工,因为类加载器检测到已经加载的 Hibernate 版本。
我什至尝试将其中每一个打包到一个单独的 EAR 中并部署它们。没有骰子。 TimerService 的加载方式似乎完全忽略了类加载隔离。
我的问题是,除了禁用 TimerService 之外,我还能做些什么吗?我打算稍后在项目中使用它的漂亮功能。老实说,我什至不知道这是否是一个错误,因为 JBoss 的类加载器文档似乎是由愤怒的克林贡人编写的。尽管如此,我还是希望能找到解决方法。
编辑 - 事实上,我什至没有办法禁用 TimerService,因为我的每一项努力都以这样或那样的方式受挫。就目前情况而言,我不知道如何将 Hibernate 和 EJB 部署到同一个 JBoss 实例。
编辑 - 我最终成功地通过不在我的 MDB 或 WAR 中包含 Hibernate jar 来进行部署,而是依靠 JBoss 的 Hibernate 实现。这是不令人满意的;我感觉容器和我的豆子之间没有隔离。但至少它是当前版本的 Hibernate (3.6)。
I've found a pretty intricate problem while working on a project with multiple EE deployables. The problem seems to be a confluence of the EJB3.1 TimerService's Hibernate dependencies and insufficient classloader isolation.
Starting with a stock AS 6 CR1 build, I deploy a WAR. This WAR contains Hibernate jars.
Then, I deploy an EJB (technically an MDB) in a JAR. When I do so, JBoss then starts up the TimerService, in order to provide full EJB3.1 support. The TimerService depends on Hibernate. JBoss then goes on strike, because the classloader detects an already loaded version of Hibernate.
I've even tried packaging each of these up into a separate EAR and deploying them. No dice. Something about the way the TimerService is being loaded seems to totally ignore classloading isolation.
My question is, is there anything I can do about it, short of disabling the TimerService? I was intending to make use of its nifty features later in the project. I honestly don't even know if this is a bug, as the classloader documentation for JBoss seems to have been written by angry Klingons. Still, I hope for a work-around.
EDIT - In fact, I don't even have a way of disabling the TimerService, as each of my efforts has been thwarted in one way or another. As it stands, I don't see how anyone can deploy Hibernate and EJBs to the same JBoss instance.
EDIT - I eventually managed to deploy by not including the Hibernate jars in my MDB or WAR, but to rely on JBoss' Hibernate implementation. This is unsatisfying; I'm left with the feeling that there's no isolation between the container and my beans. But at least it's a current version of Hibernate (3.6).
发布评论
评论(2)
不确定到目前为止您已经尝试过什么,但这应该有效:
EAR 包含:
并且还在您的 EAR 的 META-INF 中包含 jboss-app.xml:
您可能需要检查这两个页面:
http://community.jboss.org/wiki/ClassLoadingConfiguration
http://community.jboss.org/wiki/JBossClassLoadingUseCases
但我会重新考虑捆绑您自己的 Hibernate 版本的决定。虽然听起来很合理,但 AS 的作用是为您提供“应用程序托管”环境,并且它已经提供了一些服务,例如持久性。所以,把这个问题留给 AS ;-)
Not sure what you have tried so far, but this should work:
EAR containing:
And also include a jboss-app.xml in your EAR's META-INF:
You may want to check these two pages:
http://community.jboss.org/wiki/ClassLoadingConfiguration
http://community.jboss.org/wiki/JBossClassLoadingUseCases
But I would reconsider the decision of bundling your own version of Hibernate. While it may sound reasonable, the AS is there to provide you an environment of "application hosting", and it already provides some services, like persistence. So, leave this concern to the AS ;-)
我建议从 jboss 安装中删除所有 hibernate jar 的证据。我不知道为什么它们被包括在内——导致这些事情发生。 Jboss 将首先查看它自己的库,因此您肯定会遇到冲突。
此外,我知道 Jboss4 默认情况下并未配置为将每个应用程序隔离到其自己的类加载器中,因此所有类都是从同一个池加载的。不确定情况是否仍然如此,但值得调查。在安装 jboss 时,如果您愿意,您可以将其配置为隔离每个应用程序的类加载器。不过,如果 jboss common/lib 目录中有一个 hibernate 版本,隔离类加载器将无济于事。
I would suggest removing all evidence of the hibernate jars from the installation of jboss. I don't know why they're included - causes these kinds of things to happen. Jboss will look in its own libraries first so you're bound to get conflicts.
Furthermore, I know Jboss4 was not configured by default to isolate each application into its own classloader so all classes were loaded from the same pool. Not sure if this is still the case, but it's worth investigating. On install of jboss you could configure it to isolate each application's class loader if you so wished. Though if there is a version of hibernate in the jboss common/lib dir isolating the class loaders won't help.