lxm19840711 2010-01-06 16:12
浏览 218
已采纳

spring OpenSessionInViewFilter无效

在做一个项目,想通过spring 的OpenSessionInViewFilter配置解决session关闭的问题,可是配置了之后发现还是不成功,想问问大伙我的问题到底出在了哪里

项目是struts2+spring2.5+hibenate3.0.

下面是web.xml中配置的相关代码:

 <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>*.action</url-pattern>
 </filter-mapping>

 

下面是spring配置文件中关于事务的配置:

 

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <bean id="transactionManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref local="sessionFactory" />
  </property>
 </bean>
 <!-- 设置事务管理器 -->
 <bean id="transactionInterceptor"
  class="org.springframework.transaction.interceptor.TransactionInterceptor">
  <!-- 事务拦截器需要依赖一个事务管理器 -->
  <property name="transactionManager" ref="transactionManager" />
  <property name="transactionAttributes">
   <!--  下面定义事务传播属性-->
   <props>
    <prop key="delete*">PROPAGATION_REQUIRED</prop>
    <prop key="add*">PROPAGATION_REQUIRED</prop>
    <prop key="update*">PROPAGATION_REQUIRED</prop>
    <prop key="save*">PROPAGATION_REQUIRED</prop>
    <prop key="find*">PROPAGATION_REQUIRED,readOnly
    </prop>
   </props>
  </property>
 </bean>
 <bean
  class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  <!-- 定义BeanNameAutoProxyCreator-->
  <property name="beanNames">
   <!--  下面是所有需要自动创建事务代理的bean-->
   <value>*Service</value>
  </property>
  <!--  下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
  <property name="interceptorNames">
   <list>
    <value>transactionInterceptor</value>
    <!-- 此处可增加其他新的Interceptor -->
   </list>
  </property>
 </bean>

 

我在页面是想得取user类中的rose中的角度名称rname,结果显示不出--于是试着在action中进行打印该属性System.out.println(user.rose.rname) -->就指no session异常了..System.out.println(user.rose.rid) -->却可能显示...

fuser = fuserService.getFuserByUser(user.getUuser());
     if (fuser != null) {
      if (Fmd5.pwdMd5(user.getUpwd()).equals(fuser.getUpwd())) {
       System.out.println(fuser.getFrose().getRname());
       ServletActionContext.getRequest().getSession()
         .setAttribute("sessionUser", fuser);
       return SUCCESS;
      } else {
       return INPUT;
      }
     }

 

请大伙帮忙看看,非常感谢

  • 写回答

2条回答 默认 最新

  • weixin_42355128 2010-01-06 16:22
    关注

    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    放到
    org.apache.struts2.dispatcher.FilterDispatcher
    前面

    分太少,不解释!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?