我创建了一个maven项目,并通过pom.xml添加了Spring4,Hibernate4libs我尝试将我的web应用程序与在PostgreSQL中创建的数据库链接,但当我在apache tomcat 7中发布我的项目时,出现以下异常:
org.springframework.beans.factory.BeanCreationException:创建ServletContext资源[/WEB-INF/applicationContext.xml]中定义的名为“emf”的bean时出错:调用init方法失败;嵌套异常为java. lang. IllegalArgumentException:EntityManagerFactory配置中未指定PersistenceProvider,并且所选PersistenceUnitInfo在org中也未指定提供程序类名。SpringFramework豆子工厂。支持。AbstractAutowireCapableBeanFactory. initializeBean(AbstractAutowireCapableBeanFactory.java:1553)at org. SpringFramework豆子工厂。支持。AbstractAutowireCapableBeanFactory. doCreateBean(AbstractAutowireCapableBeanFactory.java:539)at org. SpringFramework豆子工厂。支持。AbstractAutowireCapableBeanFactory. createBean(AbstractAutowireCapableBeanFactory.java:475)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)at org. SpringFramework豆子工厂。支持。DefaultSingletonBeanRegistry。getSingleton(DefaultSingletonBeanRegistry.java:228)at org. SpringFramework豆子工厂。支持。AbstractBeanFactory. org上的doGetBean(AbstractBeanFactory.java:300)。SpringFramework豆子工厂。支持。AbstractBeanFactory. getBean(AbstractBeanFactory.java:195)at org. SpringFramework上下文支持。AbstractApplicationContext。getBean(AbstractApplicationContext.java:973)at org. SpringFramework上下文支持。AbstractApplicationContext。finishBeanFactoryInitialization(AbstractApplicationContext.java:750)at org. SpringFramework上下文支持。AbstractApplicationContext。在org上刷新(AbstractApplicationContext.java:482)。SpringFramework web. context. ContextLoader。org上的configureAndRefreshWebApplicationContext(ContextLoader.java:403)。SpringFramework web. context. ContextLoader。org上的initWebApplicationContext(ContextLoader.java:306)。SpringFramework web. context. ContextLoaderListener。org上的contextInitialized(ContextLoaderListener.java:106)。Apachecatalina核心StandardContext。listenerStart(StandardContext.java:4994)at org.Apachecatalina核心StandardContext。startInternal(StandardContext.java:5492)at org.Apachecatalina效用LifecycleBase. start(LifecycleBase.java:150)at org.Apachecatalina核心ContainerBase $ www.example.com EntityManagerFactory配置中未指定PersistenceProvider,并且所选PersistenceUnitInfo在org中也未指定提供程序类名。SpringFramework orm. LocalContainerEntityManagerFactoryBean。createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:318)at org. SpringFramework orm. AbstractEntityManagerFactoryBean。afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)at org. SpringFramework豆子工厂。支持。AbstractAutowireCapableBeanFactory. invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)at org. SpringFramework豆子工厂。支持。AbstractAutowireCapableBeanFactory. initializeBean(AbstractAutowireCapableBeanFactory.java:1549)...StartChild.call
下面是我applicationContext.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: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-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<context:component-scan base-package="com.medsoft.stadto">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:1993/Posts" />
<property name="username" value="postgres" />
<property name="password" value="123" />
</bean>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="emf">
<property name="packagesToScan" value="com.medsoft.stadto.entity" />
<property name="dataSource" ref="dataSource" />
<property name="jpaProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2dll.auto">create</prop>
</props>
</property>
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
3条答案
按热度按时间fcy6dtqo1#
更改
emf
bean配置并添加一个名为jpaVendorAdapter
的新bean:另外,请确保在
META-INF
目录中有一个persistence.xml
:sdnqo3pr2#
如果您没有为JPA配置JpaVendorImplementation,就会发生这种情况。下面的JPA EntityManager的Java bean定义对我来说很有用:
但下面的一个抛出了你收到的相同的异常:
请注意从第二个代码中删除的行。
yjghlzjz3#
确保像这样为
JpaPropertyMap
提供HibernatePersistenceProvider
。