我的应用程序抛出
org.springframework.beans.factory.BeanCreationException:使用名称' emf'创建bean时出错在类路径资源[datasource-tx-jpa.xml]中定义:init方法的调用失败;嵌套异常是java.lang.NoSuchMethodError:javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax / persistence / ValidationMode; 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:304) 在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 在org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973) 在org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) 在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) 在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973) 在org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467) 在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1559) 在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1549) 在java.util.concurrent.FutureTask.run(FutureTask.java:262) 在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615) 在java.lang.Thread.run(Thread.java:745) 引起:java.lang.NoSuchMethodError:javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax / persistence / ValidationMode; 在org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:642) 在org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:75) 在org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336) 在org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ......还有21个
请帮帮我, 我使用java 7,spring 4.0.0和hibernate-jpa-2.1-api(版本1.0.0.Final)
答案 0 :(得分:2)
您的CLASSPATH中有两个版本的JPA API jar,另一个版本是早期版本(JPA 1.0)。它找到了没有该方法的JPA 1.0(因为它是在JPA 2.0中引入的)。您应该只有一个版本的JPA API jar来匹配您的JPA实现。
互联网搜索也会得出相同的结论。 java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode
http://www.coderanch.com/t/620558/ORM/databases/java-lang-NoSuchMethodError-javax-persistence
答案 1 :(得分:0)
这不是正确的Hibernate依赖。您应该需要的唯一Hibernate依赖项如下(仅当您使用验证器时才是第2个):
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.7.Final</version> <!-- change version if required-->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.3.2.Final</version> <!-- change version if required-->
</dependency>
</dependencies>