日期:2014-05-17  浏览次数:20688 次

ssh session没有绑定到线程的错误
废话不多说, 直接贴配置:


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

<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>


<!-- 事务配置 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>

</bean>


<!-- 配置事务特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager" >
<tx:attributes>
<!-- 配置哪些方法将要被切入 -->
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>




<aop:config proxy-target-class="true">
<!-- 配置切入点:指哪些包下的类将要被切面所切入 第一个星号:任意返回值  第二个星号:dao包下面的子子包 第三个星号:任意类-->
<aop:pointcut id="allmethod" expression="execution(* dao.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allmethod" />
</aop:config>



spring dao层配置:
<bean id="userDao" class="dao.UserDAO">
<property name="hibernateTemplate" ref="hibernateTemplate"></property>

</bean>



web.xml配置:
<!-- spring配置 -->	
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>


<!-- spring与structs 整合的配置 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 配置spring控制session的开关 -->
  <filter>  
  <filter-name>OpenSessionInViewFilter</filter-name>   
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>   
   <!--  
    <init-param>  
       <param-name>sessionFactory</param-name>  
       <param-value>classpath:hibernate.cfg.xml</param-value>
      </init-param>
     --> 
  </filter>  
  
  <filter-mapping>  
  <filter-name>OpenSessionInViewFilter</filter-name>   
  <url-pattern>/*</url-pattern>   
  </filter-mapping>  

<!-- structs2配置 -->
<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.