0

I developed a Spring JPA project in eclipse wich access to the data stored in a mysql server. Now I need to import this project in a Spring @ MVC project. So

  1. I configure in the build path of the JPA project to export the maven dependencies
  2. I added the project to the tomcat bootstrap class path,
  3. I added the JPA/Spring project to the classpath of my Spring @MVC project
  4. I also added the jpa application context to the root-context of the MVC project.

importing the context:

<import resource="classpath:/META-INF/spring/app-context.xml"/>

. but when i start the project on the tomcat i get an error. It seems that I need to import the same libraries of the JPA project into the MVC project. Here is the error log:

GRAVE: Excepción enviando evento inicializado de contexto a instancia de escuchador de 
clase org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [META-INF/spring/app-context.xml]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: No persistence exception translators found in bean factory. Cannot perform exception translation.
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor] for bean with name 'org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor#0' defined in class path resource [META-INF/spring/app-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean] for bean with name 'entityManagerFactory' defined in class path resource [META-INF/spring/app-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.jpa.JpaTransactionManager] for bean with name 'transactionManager' defined in class path resource [META-INF/spring/app-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.jpa.JpaTransactionManager

here is my root context: http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <import resource="classpath:/META-INF/spring/app-context.xml"/>

    <!-- 
    <import resource="classpath:/META-INF/spring/app-context.xml"/>
     -->
    <!-- Root Context: defines shared resources visible to all other web components -->

</beans>

and here is my app-context of the jpa project:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <description>Example configuration to get you started.</description>

    <!-- Generic -->
    <context:annotation-config />
    <tx:annotation-driven transaction-manager="transactionManager" />

    <!-- JPA -->

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    <tx:annotation-driven />
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/> 
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true" /> <!-- Prints used SQL to stdout -->
                <property name="generateDdl" value="true" /> <!-- Generates tables. -->
                <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
            </bean>
        </property>
    </bean>
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost:3306/windydb"/>
        <property name="username" value="windyuser"/>
        <property name="password" value="maverick1984"/>
    </bean>
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <context:component-scan base-package="com.windy.spring" />

</beans>

Thanks in advance for your help

Danilo

ddelizia
  • 1,571
  • 5
  • 30
  • 54

1 Answers1

2

You've defined your transaction manager:

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
  <property name="entityManagerFactory" ref="entityManagerFactory"/> 
  <property name="dataSource" ref="dataSource"/> 
</bean> 

but Tomcat can't find the class org.springframework.orm.jpa.JpaTransactionManager. Ensure it's in your webapp's classpath.

Paul
  • 19,704
  • 14
  • 78
  • 96