看不到entityManagerFactory

时间:2011-07-10 18:24:45

标签: jpa spring-mvc

我的应用程序无法看到entityManagerFactory。在我的web.xml中:

<filter>
   <filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
   <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
   <init-param>
      <param-name>entityManagerFactoryBeanName</param-name>      
      <param-value>entityManagerFactory</param-value>       
   </init-param>
</filter>

<filter-mapping>
    <filter-name>SpringOpenEntityManagerInViewFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

在spring-servlet.xml中:

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
            <property name="showSql" value="true" />
            <property name="generateDdl" value="true" />
            <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
        </bean>
    </property>
    <property name="persistenceUnitName" value="MontyBroganPU" />
    <property name="dataSource" ref="dataSource" />

</bean>

我还是错了:

  

org.springframework.beans.factory.NoSuchBeanDefinitionException:没有定义名为'entityManagerFactory'的bean

1 个答案:

答案 0 :(得分:1)

您应该在applicationContext.xml中设置JPA-EntityManagerFactory bean,也可以使用您的dataSource bean。看看你如何做到这一点:

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/orm.html#orm-jpa-setup

相关问题