2016-02-05 164 views
-1

我使用Tomcat 7.0.67,春季4.2.0。我使用Spring的JPA,Hibernate或者JPA,但是當我嘗試啓動我的Spring應用程序失敗,出現此錯誤稱javax/persistence/EntityManagerFactory未找到類:春java.lang.NoClassDefFoundError:使用javax /持久/ EntityManagerFactory的

23:39:43.836 ERROR org.springframework.web.context.ContextLoader[] - Context initialization failed 
java.lang.NoClassDefFoundError: javax/persistence/EntityManagerFactory 
    at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.8.0_66] 
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) ~[na:1.8.0_66] 
    at java.lang.Class.getDeclaredMethods(Class.java:1975) ~[na:1.8.0_66] 
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:606) ~[spring-core-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:518) ~[spring-core-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:504) ~[spring-core-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:241) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1069) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1042) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446) ~[spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328) ~[spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107) [spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE] 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5077) [catalina.jar:7.0.67] 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5591) [catalina.jar:7.0.67] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.67] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1574) [catalina.jar:7.0.67] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1564) [catalina.jar:7.0.67] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_66] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_66] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_66] 
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_66] 
Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityManagerFactory 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_66] 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_66] 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_66] 

我嘗試添加下面我包含持久性jar的pom.xml,但它沒有區別。

<dependency> 
    <groupId>javax.persistence</groupId> 
    <artifactId>persistence-api</artifactId> 
    <version>1.0.2</version> 
</dependency> 

這是mvn dependency:tree輸出:https://gist.github.com/eytanbiala/492d9af46f8990917e45

+0

也許你使用過spring-jpa,你可能需要hibernate或eclipselink。是一個maven項目? – vels4j

+0

請提供mvn依賴項的輸出:tree? – radai

+0

我添加了mvn依賴項輸出的要點:樹 – ebi

回答

0

請tomcat的複製你的Hibernate,JPA jar文件的lib文件夾手動。

+0

這有效,但爲什麼?它似乎不應該是必要的。 – ebi

相關問題