JBoss 作用域类加载 [英] JBoss Scoped Class Loading

查看:25
本文介绍了JBoss 作用域类加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在耳朵内使用最新的hibernate版本,而不用升级服务器上的jar.我正在按照此处给出的说明进行操作 - http://jaitechwriteups.blogspot.com/2008/08/how-to-upgrade-hibernate-in-jboss.html.

I want to use the latest hibernate version inside the ear without upgrading the jars on the server. I am following the instructions given here - http://jaitechwriteups.blogspot.com/2008/08/how-to-upgrade-hibernate-in-jboss.html.

然而,现在的问题是应用程序没有使用位于部署文件夹中的 jboss-local-jdbc.rar.

However the problem now is the application is not taking the jboss-local-jdbc.rar sitting in the deploy folder.

2009-07-21 09:01:50,347 INFO  [org.jboss.system.ServiceConfigurator] Problem configuring service jboss.jca:service=DataSourceBinding,name=MockDS
org.jboss.deployment.DeploymentException: Exception setting attribute ConnectionManager = jboss.jca:service=LocalTxCM,name=MockDS on mbean jboss.jca:service=DataSourceBinding,name=MockDS; - nested throwable: (javax.management.InvalidAttributeValueException: Set attribute  has class class javax.management.ObjectName loaded from null that is not assignable to attribute class class javax.management.ObjectName loaded from org.jboss.mx.loading.UnifiedClassLoader3@1babddb{ url=file:/C:/servers/jboss-4.2.2.GA/server/default/tmp/deploy/tmp22267hibernate_upgrade_test.ear ,addedOrder=43})
    at org.jboss.system.ServiceConfigurator.setAttribute(ServiceConfigurator.java:707)
    at org.jboss.system.ServiceConfigurator.configure(ServiceConfigurator.java:382)
    at org.jboss.system.ServiceConfigurator.internalInstall(ServiceConfigurator.java:462)
    at org.jboss.system.ServiceConfigurator.install(ServiceConfigurator.java:171)
    at org.jboss.system.ServiceController.install(ServiceController.java:226)
    at sun.reflect.GeneratedMethodAccessor23.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

有什么想法吗?

推荐答案

我浏览了该页面上的说明,它主要遵循与我相同的步骤.关键的区别似乎在于他的 jboss-app.xml 文件的内容:

I had a scan through the instructions on that page, and it mostly follows the same steps that I have. The critical difference seems to be in the contents of his jboss-app.xml file:

<jboss-app>
 <loader-repository>
   org.myapp:loader=SomeClassloader
   <loader-repository-config>
      java2ParentDelegation=false
   </loader-repository-config>
 </loader-repository> 
</jboss-app>

我的系统没有禁用父委托,它只有加载器名称:

My system does not disable parent delegation, it only has the loader name:

<jboss-app>
 <loader-repository>org.myapp:loader=MyAppName</loader-repository> 
</jboss-app>

您可能(也可能不需要)还需要在 JBoss 的 deploy/ear-deployer.xml 文件中设置 Independent=true 属性:

You may (or may not) also need to set the Isolated=true attribute in JBoss's deploy/ear-deployer.xml file:

而且效果很好.通过禁用父委托,您会削弱应用程序以任何方式与容器交互的能力,这有点极端.但是,如果您忽略该选项,则需要一些牦牛剃须

And that works nicely. By disabling parent delegation, you cripple your application's ability to interact with the container in any way, which is a bit extreme. If you leave out that option, though, a bit of yak shaving is required

通过省略 java2ParentDelegation=false 选项,您会遇到这样一种情况,即 EAR 中与 JBoss 中的类同名的任何类将优先从 EAR 加载(这很好).但是,在 EAR 中找不到的任何类都将落入 JBoss 的库中.以jboss-local-jdbc.rar为例,这个不错.然而,它可能有特殊的副作用.

By leaving out the java2ParentDelegation=false option, you get a situation where any classes in your EAR which have the same name as classes in JBoss will be loaded preferentially from the EAR (which is good). However, any classes not found in the EAR will fall through to JBoss's libs. In the case of jboss-local-jdbc.rar, this is good. However, it can have peculiar side effects.

例如,当 Hibernate 创建会话工厂时,它会查找 Hibernate Search 和 Hibernate Validator 库,并尝试启动它们.如果这些不在您的 EAR 中,它会在 JBoss 的库中找到它们.问题是您经常会收到链接器错误,因为 JBoss 附带的 Search 和 Validator 版本可能与您的 EAR 中打包的 Hibernate 不兼容.

For example, when Hibernate creates a session factory, it looks for the Hibernate Search and Hibernate Validator libraries, and tries to start them up also. If these aren't present in your EAR, it will find them in JBoss's libs. The problem is that you often then get a linker error, because the versions of Search and Validator shipped with JBoss may not be compatible with the Hibernate packaged in your EAR.

对此的解决方案是配置 Hibernate 会话工厂以使用配置属性(hibernate.validator.autoregister_listeners=false> 和 hibernate.search.autoregister_listeners)禁用搜索和验证器侦听器的注册=false),或者在您的 EAR 中打包兼容版本的 Search 和 Validator.

The solution to this is to either configure the Hibernate session factory to disable registration of Search and Validator listeners using config properties (hibernate.validator.autoregister_listeners=false and hibernate.search.autoregister_listeners=false), or to package compatible versions of Search and Validator in your EAR also.

这篇关于JBoss 作用域类加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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