-1

我正在尝试将弹簧数据集成到我的项目中。在尝试这样做时,由于版本冲突,我需要升级我的许多 Maven 工件。(例如,由于 slf4j 冲突,我需要将 spring 从 3.0.3 升级到 3.1.3)。我需要将 Hibernate 从 3.5 升级到 4

现在,当我尝试将我的项目部署到 tomcat 中时,出现以下异常:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/marketplace-persist-config.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/marketplace-persist-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
       at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
       at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
       at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
       at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:734)
       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:457)
       at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
       at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
       at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4135)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4630)
       at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
       at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
       at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
       at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
       at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:525)
       at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1359)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
       at java.lang.reflect.Method.invoke(Unknown Source)
       at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
       at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
       at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
       at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1500)
       at org.apache.catalina.manager.ManagerServlet.deploy(ManagerServlet.java:670)
       at org.apache.catalina.manager.ManagerServlet.doPut(ManagerServlet.java:435)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:640)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
       at java.lang.Thread.run(Unknown Source)

我发现 Springs JPA 实体管理器没有附带 HibernateExceptionTranslater 的实现,需要手动添加。

我添加了它,但我仍然得到上述异常

这是 pom.xml 文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.comp</groupId>
    <artifactId>service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>service</name>
    <packaging>jar</packaging>
    <description>service</description>
    <url>http://www.media.com</url>
    <properties>
        <org.springframework.version>3.1.3.RELEASE</org.springframework.version>
        <spring.security.version>3.1.3.RELEASE</spring.security.version>
        <java.version>1.6</java.version>
        <servlet-api.version>2.5.0</servlet-api.version>
        <querydsl.version>2.8.2</querydsl.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>



        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.2</version>
        </dependency>


        <dependency>
            <groupId>net.sf.jxls</groupId>
            <artifactId>jxls-core</artifactId>
            <version>0.9.9</version>
            <scope>compile</scope>
        </dependency>

        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${spring.security.version}</version>
        </dependency>       

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.6</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>


        <!-- Hibernate -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>2.1_3</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.7.Final</version>
        </dependency>
<!--        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency> -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.3.0.ga</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.1.7.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>3.7-beta3</version>
        </dependency>

        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>com.springsource.javax.transaction</artifactId>
            <version>1.1.0</version>
        </dependency>

        <!-- spring dependencies -->
        <!--
            Core utilities used by other modules.
            Define this if you use Spring Utility APIs (org.springframework.core.*/org.springframework.util.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.core</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Expression Language (depends on core)
            Define this if you use Spring Expression APIs (org.springframework.expression.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.expression</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Bean Factory and JavaBeans utilities (depends on core)
            Define this if you use Spring Bean APIs (org.springframework.beans.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.beans</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

<!--        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework.version}</version>
        </dependency> -->

        <!--
            Aspect Oriented Programming (AOP) Framework (depends on core, beans)
            Define this if you use Spring AOP APIs (org.springframework.aop.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.aop</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Application Context (depends on core, expression, aop, beans)
            This is the central artifact for Spring's Dependency Injection Container and is generally always defined
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.context</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Various Application Context utilities, including EhCache, JavaMail, Quartz, and Freemarker integration
            Define this if you need any of these integrations
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.context.support</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Transaction Management Abstraction (depends on core, beans, aop, context)
            Define this if you use Spring Transactions or DAO Exception Hierarchy
            (org.springframework.transaction.*/org.springframework.dao.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.transaction</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            JDBC Data Access Library (depends on core, beans, context, transaction)
            Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.jdbc</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, and iBatis.
            (depends on core, beans, context, transaction)
            Define this if you need ORM (org.springframework.orm.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.orm</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Object-to-XML Mapping (OXM) abstraction and integration with JAXB, JiBX, Castor, XStream, and XML Beans.
            (depends on core, beans, context)
            Define this if you need OXM (org.springframework.oxm.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.oxm</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Web app development utilities common across Servlet/Portlet environments (depends on core, beans, context)
            Define this if you use Spring MVC, or wish to use Struts, JSF, or another web framework with Spring (org.springframework.web.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.web</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Spring MVC for Servlet Environments (depends on core, beans, context, web)
            Define this if you use Spring MVC with a Servlet Container such as Apache Tomcat (org.springframework.web.servlet.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.web.servlet</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Spring MVC for Portlet Environments (depends on core, beans, context, web)
            Define this if you use Spring MVC with a Portlet Container (org.springframework.web.portlet.*)
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.web.portlet</artifactId>
          <version>${org.springframework.version}</version>
        </dependency>

        <!--
            Support for testing Spring applications with tools such as JUnit and TestNG
            This artifact is generally always defined with a 'test' scope for the integration testing framework and unit testing stubs
        -->
        <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>org.springframework.test</artifactId>
          <version>${org.springframework.version}</version>
          <scope>test</scope>
        </dependency>

        <!-- Spring Data -->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.1.0.RELEASE</version>
        </dependency> 

        <!-- Query DSL -->
        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-core</artifactId>
            <version>${querydsl.version}</version>
        </dependency>

        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version>
        </dependency>

        <dependency>
            <groupId>com.mysema.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>${querydsl.version}</version>
        </dependency>

        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-utils</artifactId>
            <version>3.0.4</version>
        </dependency>  

        <dependency>
            <groupId>velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.5</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4</version>
        </dependency>


    </dependencies>
    <repositories>

        <repository>
            <id>springsource-repo</id>
            <name>SpringSource Repository</name>
            <url>http://repo.springsource.org/release</url>
        </repository>

        <repository>
            <id>com.springsource.repository.bundles.release</id>
            <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
            <url>http://repository.springsource.com/maven/bundles/release</url>
        </repository>
        <repository>
            <id>com.springsource.repository.bundles.external</id>
            <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
            <url>http://repository.springsource.com/maven/bundles/external</url>
        </repository>
        <repository>
            <id>com.springsource.repository.bundles.milestone</id>
            <name>SpringSource Enterprise Bundle Repository - External Bundle Milestones</name>
            <url>http://maven.springframework.org/milestone</url>
        </repository>
        <repository>
            <id>com.springsource.repository.bundles.milestone.alt</id>
            <name>SpringSource Enterprise Bundle Repository - External Bundle Milestones II</name>
            <url>http://repository.springsource.com/maven/bundles/milestone</url>
        </repository>
        <repository>
            <id>spring-snapshot</id>
            <name>Spring Maven SNAPSHOT Repository</name>
            <url>http://repo.springsource.org/libs-snapshot</url>
        </repository>

    </repositories>
    <build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <server>local</server>
                </configuration>
            </plugin>
            <plugin>
              <groupId>com.mysema.maven</groupId>
              <artifactId>apt-maven-plugin</artifactId>
              <version>1.0.6</version>
              <executions>
                <execution>
                  <goals>
                    <goal>process</goal>
                  </goals>
                  <configuration>
                    <outputDirectory>target/generated-sources/java</outputDirectory>
                    <!-- States that the APT code generator should look for JPA annotations --> 
                    <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                  </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
    </build>
</project>
4

1 回答 1

1

请升级以下依赖项,

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>3.3.0.ga</version>
</dependency>
于 2012-11-08T14:26:33.323 回答