2015-03-25 75 views
1

我試圖設置一個Spring MVC + Hibernate WAR來部署到Jboss 7.1.1 Final。我的應用程序使用Hibernate 3.6.1 &到目前爲止,我的理解是Hibernate 4與AS一起打包,並且是默認的持久性提供程序。我沒有使用persistent.xml文件配置。在Jboss7中配置休眠3

我遵循了在JBoss中設置Hibernate 3所需的所有步驟。

  1. 轉到AS安裝並更改到modules/org文件夾。
  2. 爲時隙3以保持休眠3
  3. 複製Hibernate3的罐子到這個新的AS /模塊創建文件夾/組織/休眠/ 3夾 (Hibernate3中-core.jar添加下,Hibernate-公地annotations.jar,hibernate3- entitymanager.jar,dom4j.jar,slf4j.jar,slf4j-api.jar,commons-collections.jar,antlr.jar,slf4j-api.jar,commons-collections.jar,antlr.jar和Hibernate所需的任何其他jar 3)
  4. 創建的AS /模塊/組織/休眠/ 3/module.xml與內容文件:

    <?xml version="1.0" encoding="UTF-8"?> 
    <module xmlns="urn:jboss:module:1.0" name="org.hibernate" slot="3"> 
        <resources> 
         <resource-root path="hibernate3-core.jar"/> 
         <resource-root path="hibernate3-commons-annotations.jar"/> 
         <resource-root path="hibernate3-entitymanager.jar"/> 
         <resource-root path="javassist-3.12.0.GA.jar"/> 
         <resource-root path="antlr-2.7.6.jar"/> 
         <resource-root path="commons-collections-3.1.jar"/> 
         <resource-root path="dom4j-1.6.1.jar"/> 
         <!-- Insert other Hibernate 3 jars to be used here --> 
        </resources> 
    
        <dependencies> 
         <module name="org.jboss.as.jpa.hibernate" slot="3"/> 
         <module name="asm.asm"/> 
         <module name="javax.api"/> 
         <module name="javax.persistence.api"/> 
         <module name="javax.transaction.api"/> 
         <module name="javax.validation.api"/> 
         <module name="org.apache.ant"/> 
         <module name="org.infinispan"/> 
         <module name="org.javassist"/> 
         <module name="org.slf4j"/> 
        </dependencies> 
    </module> 
    

我的pom.xml(部分):

<!-- Hibernate dependencies --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>3.6.6.Final</version> 
     <exclusions> 
      <exclusion> 
       <groupId>xml-apis</groupId> 
       <artifactId>xml-apis</artifactId> 
      </exclusion> 
     </exclusions> 
     <scope>compile</scope> 
    </dependency> 
    <dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-annotations</artifactId> 
    <version>3.5.6-Final</version> 
</dependency> 
<dependency> 
    <groupId>javax.persistence</groupId> 
    <artifactId>persistence-api</artifactId> 
    <version>1.0.2</version> 
</dependency> 
<dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-validator</artifactId> 
     <version>3.0.0.ga</version> 
    </dependency> 
    <dependency> 
    <groupId>org.hibernate.common</groupId> 
    <artifactId>hibernate-commons-annotations</artifactId> 
    <version>4.0.5.Final</version> 
    </dependency> 

我休眠-context.xml的(部分)

<jpa:repositories base-package="com.gea.dvr.repository" /> 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" 
       p:dataSource-ref="dataSource" 
       p:configLocation="${hibernate.config}" 
       p:packagesToScan="com.iana.dver"/> 

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" 
       p:driverClass="${app.jdbc.driverClassName}" 
       p:jdbcUrl="${app.jdbc.url}" 
       p:user="${app.jdbc.username}" 
       p:password="${app.jdbc.password}" 
       p:idleConnectionTestPeriod="30" 
       p:maxPoolSize="100" 
       p:maxStatements="50" 
       p:minPoolSize="10" 
       p:maxIdleTime="60" /> 

    <!-- Declare a transaction manager--> 
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
       p:sessionFactory-ref="sessionFactory" />      

    <!-- Specify our ORM vendor --> 
    <bean id="hibernateVendor" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" 
       p:showSql="false"/> 

我的hibernate.cfg.xml

<hibernate-configuration> 
    <session-factory name="sessionFactory"> 
    <!-- We're using MySQL database so the dialect needs to MySQL as well--> 
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
    <!-- Enable this to see the SQL statements in the logs--> 
    <property name="show_sql">false</property> 
    <!-- This will drop our existing database and re-create a new one. 
      Existing data will be deleted! --> 
    <!-- <property name="hbm2ddl.auto">update</property>--> 

    <mapping class="com.gea.dvr.domain.DvrUserType"/> 
    <mapping class="com.gea.dvr.domain.DvrUsers"/> 
    <mapping class="com.gea.dvr.domain.DvrConfig"/> 
    <mapping class="com.gea.dvr.domain.DvrDetail"/> 
    <mapping class="com.gea.dvr.domain.DvrFiles"/> 
    <mapping class="com.gea.dvr.domain.DvrNotif"/> 
    <mapping class="com.gea.dvr.domain.UserLogin"/> 
    </session-factory> 
</hibernate-configuration> 

我已經提供了所有需要java仍然我仍然得到異常, 任何人都可以幫助我在JBoss中設置hibernate 3相關的變化?

11:03:14,597 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-3) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateVendor' defined in ServletContext resource [/WEB-INF/hibernate-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/ejb/HibernatePersistence 

回答

1

既然你得到一個java.lang.NoClassDefFoundError(而不是一個ClassNotFoundException),它可能是某種形式的類加載問題。

嘗試添加將解決您的問題的hibernate-entitymanager依賴項。

<dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-entitymanager</artifactId> 
    <version>${hibernate.version}</version> 
    <exclusions> 
     <exclusion> 
      <groupId>cglib</groupId> 
      <artifactId>cglib</artifactId> 
     </exclusion> 
     <exclusion> 
      <groupId>dom4j</groupId> 
      <artifactId>dom4j</artifactId> 
     </exclusion> 
    </exclusions> 
</dependency> 
+0

我試過你的解決方案,它的工作完美。 – 2015-03-25 10:13:44