spring data jpa 中的OpenEntityManagerInViewFilter 取代OpenSessionInViewFilter 放置session失效

spring 中 正常的防止session失效的方法是:

<!-- 配置session防止session失效 -->
	<filter>
		<filter-name>hibernateFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
		<init-param>  
        <param-name>sessionFactoryBeanName</param-name>  
        <param-value>sessionFactory</param-value>  
    </init-param>  
	</filter>
	<filter-mapping>
		<filter-name>hibernateFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>


在 spring data jpa 中 用的是:

filter>  
        <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>  
        <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>  
        <init-param>  
        <!-- 指定org.springframework.orm.jpa.LocalEntityManagerFactoryBean在spring配置文件中的名称,默认值为entityManagerFactory  
        如果LocalEntityManagerFactoryBean在spring中的名称不是entityManagerFactory,该参数一定要指定,否则会出现找不到entityManagerFactory的例外 -->  
            <param-name>entityManagerFactoryBeanName</param-name>  
            <param-value>entityManagerFactory</param-value>  
        </init-param>   
    </filter>  
    <filter-mapping>  
        <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  


你可能感兴趣的:(spring data jpa 中的OpenEntityManagerInViewFilter 取代OpenSessionInViewFilter 放置session失效)