接上贴:http://topic.csdn.net/u/20090719/19/7e932bea-1104-48db-b447-9a697dcdf522.html 在网上找了很多关于配置OpenSessionInViewFilter 的文章,貌似只要在web.xml中加: <filter> 
<filter-name>OpenSessionInViewFilter </filter-name> 
<filter-class> 
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter 
</filter-class> <init-param> 
<param-name>singleSession </param-name> 
<param-value>true </param-value> 
</init-param> 
</filter> 
<filter-mapping> 
<filter-name>OpenSessionInViewFilter </filter-name> 
<url-pattern>*.do </url-pattern> 
</filter-mapping> 
<listener> 
<listener-class> 
org.springframework.web.context.ContextLoaderListener 
</listener-class> 
</listener> 
<context-param> 
<param-name>contextConfigLocation </param-name> 
<param-value>/WEB-INF/applicationContext*.xml </param-value> 
</context-param> 就可以了,但为什么还是org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role这个呢? 请高手指教:配置OpenSessionInViewFilter,除了设置web.xml外,还要下载其他包或者加其他代码吗? 
已经有spring.jar 求详细配置方法和使用代码,这个问题困扰我好几天了,类似的问题也问了好几个,都是一两句话解答,还是没有头绪,请告诉我具体怎么做,不要一两句话太抽象,谢谢:)

解决方案 »

  1.   


    <beans> 
      <bean name="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"> 
      <property name="sessionFactory"> 
      <ref bean="sessionFactory"/> 
      </property> 
      </bean> 
      <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
      <property name="interceptors"> 
      <list> 
      <ref bean="openSessionInViewInterceptor"/> 
      </list> 
      </property> 
      <property name="mappings"> 
      ...... 
      </property> 
      </bean> 
      ...... 
      </beans> 
      OpenSessionInViewFilter配置: 
      <web-app> 
      ...... 
      <filter> 
      <filter-name>hibernateFilter</filter-name> 
      <filter-class> 
      org.springframework.orm.hibernate3.support.OpenSessionInViewFilter 
      </filter-class> 
      <init-param> 
      <param-name>singleSession</param-name> 
      <param-value>true</param-value> 
      </init-param> 
      </filter> 
      ...... 
      <filter-mapping> 
      <filter-name>hibernateFilter</filter-name> 
      <url-pattern>*.do</url-pattern> 
      </filter-mapping> 
      ...... 
      </web-app>