JBoss4.2.3部署SSH2

  1. 部署环境:JDK1.6+JBoss4.2.3+Struts2.1.8+Spring2.5.6+Hibernate3.3.2。
  2. 将war包解压至“JBOSS安装目录\server\default\deploy”目录下,文件夹改名为xxx.war,或者直接将war包拷贝到该目录。
  3. 启动JBoss,报了很多错误。主要错误摘要如下:
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [spring/applicationContext-hibernate.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring/applicationContext-hibernate.xml]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
    .....................
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [spring/applicationContext-hibernate.xml]: Invocation of init method failed; nested exceptionis org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle,org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1338)
    .....................
    Caused by: org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager)
            at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:374)
    .....................
    Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map, org.hibernate.annotations.common.reflection.ReflectionManager) 
            at java.lang.Class.getConstructor0(Class.java:2706)
            at java.lang.Class.getDeclaredConstructor(Class.java:1985)
            at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:362)
            ... 214 more
     
  4. 修改“JBOSS安装目录\server\default\deploy\jboss-web.deployer\META-INF”下的jboss-service.xml文件,改属性“UseJBossWebLoader”为true。
    该属性原文解释如下:
    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.
    The default is false to ensure that wars have isolated class loading for duplicate jars and jsp files.

    该配置表明是否使用JBoss自身的classloader来加载webApp相关的资源;因为JBoss是通过集成Tomcat来实现Web Container的,而两者都有自己独立的classloader;
    若设置为true,则表示Web应用加载时都将使用JBoss统一的classloader,即此时采用共享的扁平的UnifiedClassLoader;
    若设置为false,则表示Web应用采用自己独立的WebAppClassLoader进行加载,此时Web应用和JBoss之间是完全隔离的,这也是该配置项的默认值;
  5. 新启动正常,无错误日志,访问部署的Web应用正常。

你可能感兴趣的:(java,spring,Hibernate,bean,jboss)