[原创] Hibernate Open Session In View 的完整配置信息 跑通无误!

web.xml 注意两个filter的顺序 位置放反会报no session的异常

<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>/*</url-pattern>     
 </filter-mapping>
 
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.FilterDispatcher
  </filter-class>
 </filter>
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

ApplicationContext.xml

<bean id="baseTransaction" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
 <property name="transactionManager" ref="transactionManager"/>
 <property name="proxyTargetClass" value="true"/>
 <property name="transactionAttributes">
  <props>
  <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
  <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
  <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
  <prop key="save*">PROPAGATION_REQUIRED</prop>
  <prop key="add*">PROPAGATION_REQUIRED</prop>
  <prop key="update*">PROPAGATION_REQUIRED</prop>
  <prop key="remove*">PROPAGATION_REQUIRED</prop>
  </props>
 </property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref local="sessionFactory" />
  </property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation" value="classpath:hibernate.cfg.xml">
  </property>
</bean>

<bean id="userService" parent="baseTransaction">
       <property name="target">
            <bean class="com.taoxiaobao.business.UserServiceImpl">
                 <property name="userDAO" ref="userDAO" />
            </bean>
       </property>
</bean>

<bean id="productService" parent="baseTransaction">
       <property name="target">
            <bean class="com.taoxiaobao.business.ProductServiceImpl">
                 <property name="productDAO" ref="productDAO" />
            </bean>
       </property>
</bean>
 
<bean id="userDAO" class="com.taoxiaobao.db.dao.UserDAO" >
 <property name="sessionFactory">
   <ref bean="sessionFactory" />
   </property>
</bean> 
<bean id="productDAO" class="com.taoxiaobao.db.dao.ProductDAO" >
 <property name="sessionFactory">
   <ref bean="sessionFactory" />
   </property>
</bean> 


<bean name="loginAction" class="com.taoxiaobao.web.action.LoginAction" scope="prototype">
 <property name="userService">
  <ref bean="userService"/>
 </property>
</bean>
<bean name="showProductListAction" class="com.taoxiaobao.web.action.ShowProductListAction" scope="prototype">
 <property name="productService">
  <ref bean="productService"/>
 </property>
</bean>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值