spring 懒加载

所谓懒加载(lazy)就是延时加载,延迟加载

在springIOC容器中,可以通过设置<beans default-lazy-init="XXX"></beans>来设置是否为懒加载模式,懒加载的意思就是说是否在spring容器加载的时候将bean加载到容器中。在没有设置的情况下,默认是false的,就是说不使用懒加载模式。

至于为什么要用懒加载呢,就是当我们要访问的数据量过大时,明显用缓存不太合适,
因为内存容量有限 ,为了减少并发量,减少系统资源的消耗,
我们让数据在需要的时候才进行加载,这时我们就用到了懒加载。

 <filter>
         <filter-name>OpenSessionInViewFilter</filter-name>
         <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
          <init-param>
           <param-name>flushMode</param-name>
            <param-value>AUTO</param-value>
        </init-param>
     </filter>

     <filter-mapping>
         <filter-name>OpenSessionInViewFilter</filter-name>
         <url-pattern>*.action</url-pattern>
     </filter-mapping>

这个过滤器可以解决懒加载问题但是必须配置在Struts2的核心的过滤器之前!

Spring中,applicationContext.xml 配置文件在web.xml中的配置详解

原文地址:https://www.cnblogs.com/han-java/p/9615981.html