NoClassDefFoundError:在Web服务模块中导入jpa应用程序上下文时,javax / persistence / Converter

问题描述 投票:-1回答:2

从多模块maven项目中的webservice模块调用jpa模块时出现以下错误。

org.springframework.beans.factory.BeanCreationException:创建在类路径资源[spring / applicationContext-mysql.xml]中定义的名称为'entityManagerFactory'的bean时出错:调用init方法失败;嵌套的异常是java.lang.NoClassDefFoundError:javax / persistence / Converter

我在webservice模块的spring-ws-servlet.xml文件中添加了资源导入

<?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:sws="http://www.springframework.org/schema/web-services" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.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.learn.spring" />

  <sws:annotation-driven/>

  <sws:dynamic-wsdl id="osinvoke" portTypeName="EAIOSInvoke" locationUri="/osinvoke/" targetNamespace="http://spring.learn.com/eai/definitions">
    <sws:xsd location="/WEB-INF/osinvoke.xsd" />
  </sws:dynamic-wsdl>

  <import resource="classpath:/spring/applicationContext-mysql.xml" />
</beans>

这是jpa模块中的applicationContext-mysql.xml文件

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

  <tx:annotation-driven />
  <context:annotation-config />
  <context:component-scan base-package="org.learn.spring" />

  <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/cmddb" />
    <property name="username" value="testdb" />
    <property name="password" value="testpass" />
  </bean>

  <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="jpaData" />
    <property name="jpaVendorAdapter">
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
    </property>
    <property name="jpaProperties">
      <props>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="hibernate.format_sql">false</prop>
        <prop key="hibernate.hbm2ddl.auto">validate</prop>
      </props>
    </property>
  </bean>

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

</beans>

jpa模块中的单元测试能够检测应用程序上下文并从上下文文件创建实体管理器。 Web服务模块无法创建entityManagerFactory对象。

java spring maven jpa classpath
2个回答
1
投票

从TomEE切换到Tomcat修复了类路径错误。进一步研究类路径问题,TomEE中有一个maven plugin来帮助configuration of jars。谢谢您的帮助。


0
投票

您的JPA提供程序需要JPA 2.1,并且您的CLASSPATH中没有该jar(相反,您有一个较早的JPA API jar)。这种问题已经在这里问过很多次了>


0
投票

您的类路径中有多个JPA提供程序。或至少位于您的Application Server lib文件夹中。

© www.soinside.com 2019 - 2024. All rights reserved.