标签:hibernate spring web.xml struts
    最近在知乎看到一句话,保持学习的有一种是你看到了更多的牛人,不甘心,真的不甘心。
Spring和hibernate整合的时候,jsp页面做展现,发现展现属性出现:
解决的办法就是就是写多一个filter,名字也很直观
<filter>
     <filter-name >openSessionInview </filter-name>
     <filter-class >org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
   
</filter >
<filter-mapping >
          <filter-name> openSessionInview</filter-name >
          <url-pattern> /*</ url-pattern>
</filter-mapping >
在展现层打开session,当然要写在struts的过滤之前,因为责任链的存在,先读取的反而是后实现的。
就在觉得配完之后没问题的时候,有一个问题出现了,发现sessionFactory没有注入,因为我sessionFactory的id给我简写成sf,然后就猜到,应该是OpenSessionInViewFilter这个类需要注入sessionFactory,该类也有get方法,但是名字不匹配,所以注入失败。
后面尝试用
<bean id="openSessionInview" class="org.springframework.orm.hibernate3.support.OpenSessionInViewFilter ">
          <property name="sessionFactory" ref="sf"></property>
</bean>
<filter>
     <filter-name >openSessionInview </filter-name>
     <filter-class >org.springframework.orm.hibernate3.support.OpenSessionInViewFilter </filter-class>
     <init-param >
           <param-name> sessionFactoryBeanName</param-name >
          <param-value> sf</param-value >
     </init-param >
</filter >
<filter-mapping >
          <filter-name> openSessionInview</filter-name >
          <url-pattern> /*</ url-pattern>
</filter-mapping >
Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题,布布扣,bubuko.com
Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题
标签:hibernate spring web.xml struts
原文地址:http://blog.csdn.net/iaiti/article/details/27976473