我在applicationContext.xml中添加PersistenceExceptionTranslationPostProcess时出现ClassNotFoundException

时间:2015-05-11 08:37:52

标签: hibernate spring-mvc exception jpa

我想在我的应用程序中包含PersistenceExceptionTranslationPostProcessor。

我有一个网络项目和一个ejb项目

在网络项目中,我添加了 applicationContext.xml

<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

并在 web.xml 中设置

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/dispatcher-config.xml,
            /WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

然后,在ejb项目中,我有 pom.xml ,如下所示:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>3.2.3.RELEASE</version>
        <scope>provided</scope>
    </dependency>

并拥有带@repository注释的类。因此,当我启动Web应用程序时,出现以下错误:

java.lang.ClassNotFoundException: org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor

如果我从web.xml中删除了application.xml的加载,则错误消失。 有谁知道这个问题的正确配置?

这是网络层的pom

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>com.app</groupId>
        <artifactId>delegate</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.5.2</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.2</version>
    </dependency>
    <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>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>3.1</version>
    </dependency>
</dependencies>

这是代表级别的pom

<dependency>
<groupId>com.app</groupId>
<artifactId>ejb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>ejb</type>

这是ejb等级的pom

<dependency>
   <groupId>org.jboss.spec.javax.ejb</groupId>
   <artifactId>jboss-ejb-api_3.1_spec</artifactId>
   <version>1.0.1.Final</version>
</dependency>
<dependency>
    <groupId>com.app</groupId>
    <artifactId>ejb-util</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.3.8.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.spec.javax.annotation</groupId>
    <artifactId>jboss-annotations-api_1.1_spec</artifactId>
    <version>1.0.0.Final</version>
<scope>provided</scope>

最后这是ejb-util的pom

<dependency>
   <groupId>org.jboss.spec.javax.ejb</groupId>
   <artifactId>jboss-ejb-api_3.1_spec</artifactId>
   <version>1.0.1.Final</version>
</dependency>
<dependency>
    <groupId>org.jboss.spec.javax.interceptor</groupId>
    <artifactId>jboss-interceptors-api_1.1_spec</artifactId>
    <version>1.0.0.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>4.2.11.Final</version>
    <scope>provided</scope>
</dependency>
<dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>3.2.3.RELEASE</version>
    <scope>provided</scope>
</dependency>  

这是耳朵

<dependency>
    <groupId>com.app</groupId>
    <artifactId>web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>war</type>
</dependency>
<dependency>
    <groupId>com.app</groupId>
    <artifactId>ejb</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>ejb</type>
</dependency>

1 个答案:

答案 0 :(得分:1)

如下所示,您将在spring-tx包中找到此类:

https://repository.sonatype.org/index.html#nexus-search;classname~org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor

因此,如果您将以下内容添加到POM中,它应该可以工作:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-tx</artifactId>
  <version>3.2.3.RELEASE</version>
</dependency>