
web.xml 的配置文件
<!-- 配置SPRing解決懶加載問題的過濾器 --> <filter> <filter-name>OpensessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <!-- 配置Struts2的主過濾器 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
注意 : 一定要配置在struts過濾器的上面, 否則不起作用
使用了OpenSessionInView模式可能造成內存和數據庫連接問題 由于使用了OpenSessionInView模式,Session的生命周期變長。雖然解決了Lazy Load的問題,但是帶來的問題就是Hibernate的一級緩存,也就是Session級別的緩存的生命周期會變得非常長,如果在Service層做大批量的數據操作時,其實這些數據會在緩存中保留一份,這是非常耗費內存的。還有一個數據庫連接的問題,存在的原因在于由于數據庫的Connection是和Session綁在一起的,所以,Connection也會得不到及時的釋放。因而當系統出現業務非常繁忙,而計算量又非常大的時候,數據連接池的連接數會不夠
新聞熱點
疑難解答