0

我在设置 spring mvc 3 和使用自动 dll 休眠时遇到问题,这是我的文件夹结构: 文件夹结构

这些是我的图书馆:

图书馆

抽象用户

package org.andreadorigo.abstracts;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

/**
 * Generic user
 * @author andreadorigo
 *
 */

public abstract class AbstractUser {
    @Id
    @Column(name="id")
    @GeneratedValue
    private Integer id;

    @NotEmpty
    @Email
    @Column(name="email")
    public String email;

    @NotEmpty
    @Size(min = 6, max = 14)
    @Column(name="password")
    public String password;

    /**
     * 
     */
    public AbstractUser() {
        super();
    }


    //Getters and setters
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }



}

客户用户

package org.andreadorigo.entities;

import javax.persistence.Entity;
import javax.persistence.Table;

import org.andreadorigo.abstracts.AbstractUser;

@Entity
@Table(name="customerUser")
public class CustomerUser extends AbstractUser{

}

调度程序-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">


    <context:component-scan base-package="org.andreadorigo" />
    <mvc:annotation-driven />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
        <property name="prefix">
            <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <bean
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    id="entityManagerFactory">
        <property
            name="persistenceUnitName"
            value="jtdb" />

        <property
            name="dataSource"
            ref="dataSource" />

        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

        <property
            name="showSql"
            value="true" />

        <property
            name="generateDdl"
            value="true" />

        <property
            name="databasePlatform"
            value="org.hibernate.dialect.MySQLDialect" />
        </bean>
    </property>

    <property name="jpaProperties">
        <props>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
        </props>
    </property>
</bean>
</beans>

休眠.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <property name="connection.url">jdbc:mysql://localhost:3306/test</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="transaction.factory_class">org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory</property>
        <property name="hibernate.hbm2ddl.auto">create</property>
    </session-factory>
</hibernate-configuration>

持久性.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">

    <persistence-unit name="CustomerUser">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>org.andreadorigo.entities.CustomerUser</class>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        </properties>
    </persistence-unit>

</persistence>

但是当我运行 jboss 7 时,我得到了这些警告/错误:

15:48:57,442 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
    15:48:58,322 INFO  [org.hibernate.validator.util.Version] (MSC service thread 1-2) Hibernate Validator 4.2.0.Final
15:48:59,172 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)

15:48:59,614 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-2) Monitoring jndi:/default-host/GenericProject/WEB-INF/faces-config.xml for modifications
15:49:00,295 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
    15:49:00,405 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /GenericProject
15:49:01,010 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)

15:49:01,271 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)

15:49:01,529 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)

15:49:01,778 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (MSC service thread 1-3) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
15:49:01,795 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)

15:49:02,061 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:02,310 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@55e3c942: defining beans [registerController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,viewResolver,entityManagerFactory]; root of factory hierarchy
15:49:02,374 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
    15:49:02,749 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
15:49:03,126 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.AbstractEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/AbstractEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)
    15:49:03,505 WARN  [org.jboss.modules] (MSC service thread 1-3) Failed to define class org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in Module "deployment.SpringTest.war:main" from Service Module Loader: java.lang.LinkageError: Failed to link org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean (Module "deployment.SpringTest.war:main" from Service Module Loader)

15:49:03,839 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@55e3c942: defining beans [registerController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.validation.beanvalidation.LocalValidatorFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,viewResolver,entityManagerFactory]; root of factory hierarchy
15:49:03,875 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroy method on bean with name 'org.springframework.web.servlet.handler.MappedInterceptor#0' threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization

15:49:04,031 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroy method on bean with name '(inner bean)' threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization


15:49:04,182 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroy method on bean with name 'org.springframework.format.support.FormattingConversionServiceFactoryBean#0' threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization
    15:49:04,381 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] (MSC service thread 1-3) Destroy method on bean with name 'registerController' threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization

15:49:04,530 ERROR [org.springframework.web.servlet.DispatcherServlet] (MSC service thread 1-3) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]

15:49:04,868 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringTest]] (MSC service thread 1-3) StandardWrapper.Throwable: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]


15:49:05,194 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/SpringTest]] (MSC service thread 1-3) Servlet /SpringTest threw load() exception: java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean from [Module "deployment.SpringTest.war:main" from Service Module Loader]
4

2 回答 2

1

这里至少有两件事错了

  1. 您正在混合 spring 版本 3.0.3 和 3.1.1,永远不要混合不同的 spring 版本(实际上这适用于所有框架)。
  2. 您至少缺少 spring-tx.jar 和 spring-aop.jar。

我强烈建议使用MavenGradle来管理您的依赖项,这样可以省去在 Internet 上搜索 jar 的麻烦。

接下来,决定要使用什么进行配置,您可以通过 hibernate.cfg.xml、spring 上下文文件和 persistence.xml 配置您的 entitymanager。为什么?至少删除 hibernate.cfg.xml 并将所需的配置放在 persistence.xml 中。

于 2013-09-13T14:19:27.253 回答
0

鉴于这一行,您似乎缺少spring-tx类路径中的 jar

15:49:04,031 ERROR [org.springframework.beans.factory.support.DefaultListableBeanFactory] 
(MSC service thread 1-3) Destroy method on bean with name '(inner bean)' 
threw an exception: java.lang.NoClassDefFoundError: org/springframework/transaction/support/TransactionSynchronization

你可以在这里得到它。

实际上,您似乎缺少的远不止这些。

java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean 

从这里得到所有的弹簧罐。

于 2013-09-13T14:15:37.823 回答