web.xml
<filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>xxx.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
1.当一个url请求 ==> 在OpenSessionInViewFilter下doFilter()方法开启session(注:查找sessionFactory时,名称写死"sessionFactory") ==> 执行struts2核心流程 ==> 执行Struts2过滤器下OpenSessionInViewFilter下finally方法,把actionContext清空 ==> 执行页面,此时session未关闭 ==> 该模式下finally{关闭session}
2.该模式下提前打开session,延迟关闭session,解决懒加载
同时延长一级缓存生命周期,对内存消耗较大