SSH由WAS/Tomcat/Weblogic迁移到JBOSS

又是一个凌晨,又一次搞项目在新的中间件上的可部署性验证。。。

原来将项目部署到was7上,花了三个晚上到凌晨1点多的时间,总结出了只要将common-logging和wodenxx.jar两个jar包放到was7的java/lib/ext目录下,即可解决所有问题。今天又花了一晚上的时间,总结出如下几点经验(部分摘录自网上):

1、Hibernate不兼容

     由于项目使用的是hibernate3.6.10Final,而jboss eap 5.1.2使用的hibernate为3.3,所以项目中如果存在有关于hibernate的相关jar包,会有冲突。具体引起冲突的jar包为hibernate.annotations.jar,在这里不解决为什么会有冲突了,有兴趣的可以尝试将新版本的hibernate.annotations.jar放到项目的web-inf/lib下,启动后看看和原来的日志信息有什么区别,再看看这个问题,如果不用删除所有web-inf/lib下的jar包的解决方案的话,有没有其他的解决方案?

   结论:

    解决方案1:删除WEB-INF/lib下的所有跟hibernate相关的jar包(如果WEB-INF/lib下的所有包都正常,那么为了保证项目在其他中间件上部署时正常,请直接看2、类加载的问题吧,用这个解决方案会更省事!)

    解决方案2:升级为hibernate4,但是要考虑程序也要升级

2、类加载的问题

如果项目启动时报类似以下的错误:

java.lang.LinkageError: loader constraint violation: when resolving interface method "org.hibernate.engine.SessionFactoryImplementor.getTransactionManager()Ljavax/transaction/TransactionManager;" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, org/springframework/orm/hibernate3/SessionFactoryUtils, and the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) for resolved class, org/hibernate/engine/SessionFactoryImplementor, have different Class objects for the type javax/transaction/TransactionManager used in the signature

这个问题耗费了我很长一段时间,查阅了很多论坛和技术资料,也用了很多的解决办法,如把Jar包替换掉,查找配置文件……。最后在http://www.jboss.org/community/wiki/ClassLoadingConfiguration 中找到解决方法。

最终的方案就是在项目的WEB-INF下面添加了一个叫jboss-web.xml的文件,内容如下:

<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN"   
"http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">  
<jboss-web>  
<class-loading java2ClassLoadingCompliance='true'>  
       <loader-repository>  
           com.example:archive=unique-archive-name   
           <loader-repository-config>  
               java2ParentDelegaton=true  
           </loader-repository-config>  
       </loader-repository>  
  </class-loading>  
</jboss-web>

可以解决问题。

原文地址:https://www.cnblogs.com/hanxianlong/p/3427419.html