2012-02-15 71 views
0

由於延遲加載問題,休眠我嘗試設置彈簧OpenEntityManagerInViewFilter。在我的項目中使用OpenEntityManagerInViewFilter?

但我不能把它與我已經工作程序工作。 從添加的東西web.xml和創造的applicationContext.xml來我所要做的,爲了使用Open EM還有什麼APPART?

感謝

我已經加入到web.xml文件:

<filter> 
     <filter-name> 
      OpenEntityManagerInViewFilter 
     </filter-name> 
      <filter-class> 
       org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter 
      </filter-class> 
      <init-param> 
       <param-name>singleSession</param-name> 
       <param-value>true</param-value> 
      </init-param> 
      <init-param> 
       <param-name>flushMode</param-name> 
       <param-value>AUTO</param-value> 
      </init-param> 
    </filter> 
    <!-- Include this if you are using Hibernate --> 
    <filter-mapping> 
     <filter-name>OpenEntityManagerInViewFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <!-- Spring config --> 
    <listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

    <listener> 
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> 
    </listener> 

和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:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"> 

</beans> 

我已經可以部署我的應用程序,但是當我嘗試推出它拋出例如:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' is defined 

回答

0

創建的entityManagerFactory加入這個初始參數到配置到你的applicationContext.xml這樣的:

<!-- Add JPA support --> 
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
    <property name="loadTimeWeaver"> 
     <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/> 
    </property> 
</bean> 

<!-- Add Transaction support --> 
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
    <property name="entityManagerFactory" ref="entityManagerFactory"/> 
</bean> 
0

由於錯誤提示你沒有在你的spring配置文件中定義的entityManagerFactory。或者用其他名稱定義。嘗試在web.xml

<init-param> 
    <param-name>entityManagerFactoryBeanName</param-name> 
    <param-value>entityManagerFactory</param-value> 
</init-param> 
相關問題