J2EE程序从JBoss4.0.0及3.2.x升级到4.0.1+的问题解决办法

在JBoss的文档中,宣称JBoss4.0版本是业界第一个支持J2EE1.4规范的应用服务器。以前公司的很多程序都是在JBoss3.2.x的版本上开发的,所以就想把他们移植到JBoss4.0.2中。于是,我就把预案原来程序原封不动的copy到JBoss4.0.2的default/deploy目录中,但是运行时却怎么也出不来结果。最后通过一步步跟踪,发现程序在获得EJB的home接口时发生了异常,异常类型为ClassCastException——类型转换错误。
在JBoss的服务器类型中一般会包含三种配置:default、minimal和all,这种配置方式在3.2和4.0.1+中都是一致,但是有一个版本例外,那就是4.0.0。在4.0.0中包含了4种服务器配置:default、minimal、all和standard。在4.0.0中standard配置就相当于3.2和4.0.1+中的default配置,而4.0.0中的defaut配置和standard配置是一样的,除了default完全兼容于J2EE1.4规范。在3.2和4.0.1+的default配置中以及4.0.0的standard配置中,JBoss在它的统一标准的类装载器里启动所有的J2EE服务。这样,当所有组件都发布在同一个JVM中时,它就会获得最优化的性能。但是,在JBoss的这种配置中,被发布的应用程序并没有被严格划分。于是就导致这种配置并不能完全适应J2EE1.4的规范。因此当我们把程序直接copy过来时才会发生异常。为了使这种配置完全适应J2EE规范,我们必须按照以下的步骤修改配置文件的设置,使范围类装载行为和通过值调用的JNDI查找行为起作用。
第一步,编辑conf/jboss-services.xml文件,将NamingService的CallByValue属性的值设置为true。
<mbean code="org.jboss.naming.NamingService"
name="jboss:service=Naming">
<!-- The call by value mode. true if all lookups are unmarshalled using
the caller's TCL, false if in VM lookups return the value by reference.
-->
<attribute name="CallByValue">true</attribute>
...
</mbean>
第二步,编辑deploy/ear-deployer.xml文件,设置Isolated和CallByValue属性的值为true。
<server>
<!-- EAR deployer, remove if you are not using ear deployments -->
<mbean code="org.jboss.deployment.EARDeployer"
name="jboss.j2ee:service=EARDeployer">
<!-- A flag indicating if ear deployments should have their own scoped
class loader to isolate their classes from other deployments.
-->
<attribute name="Isolated">true</attribute>
<!-- A flag indicating if the ear components should have in VM call
optimization disabled.
-->
<attribute name="CallByValue">true</attribute>
</mbean>
</server>
最后,编辑deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml文件,设置Java2ClassLoadingCompliance和UseJBossWebLoader属性的值为true。
<server>
<mbean code="org.jboss.web.tomcat.tc5.Tomcat5"
name="jboss.web:service=WebServer">
<!-- Get the flag indicating if the normal Java2 parent first class
loading model should be used over the servlet 2.3 web container first
model.
-->
<attribute name="Java2ClassLoadingCompliance">true</attribute>
<attribute name="LenientEjbLink">true</attribute>
<!-- A flag indicating if the JBoss Loader should be used. This loader
uses a unified class loader as the class loader rather than the tomcat
specific class loader.
-->
<attribute name="UseJBossWebLoader">true</attribute>
经过以上步骤地修改以后,这个配置就完全适应J2EE规范了,升级时出现的问题也就顺利解决了。
来自:[url=http://dev.10086.cn/cmdn/bbs/viewthread.php?tid=22836&extra=page%3D1%26amp%3Borderby%3Ddateline]中国移动开发者社区[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值