Struts+Hibernate+Spring整合

一:在web.xml文件中的配置
<!—文本参数 -->
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext*.xml</param-value>
   </context-param>
  
<!-- 监听器 在Sprint web Libraries包下,sprint-web.jar下,contxt包中 -->
   <listener>
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>
  
   <!-- 过滤器  在Sprint web Libraries包下,sprint-web.jar下,filter包中 -->
  
   <filter>
         <filter-name>econdingFilter</filter-name>
         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
         <init-param>
           <param-name>encoding</param-name>
           <param-value>utf-8</param-value>
         </init-param>
        
         <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
         </init-param>
   </filter>
  
   <filter-mapping>
       <filter-name>econdingFilter</filter-name>
       <url-pattern>*.do</url-pattern>
   </filter-mapping>

<!—延迟加载过滤器  在Spring Persistence包下,spring-orm.jar中,hibernate3.support文件包中-->
   <filter>
      <filter-name>openSessionInViewFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
   </filter>
   <filter-mapping>
       <filter-name>openSessionInViewFilter</filter-name>
       <url-pattern>*.do</url-pattern>
   </filter-mapping>
二:在Struts-config-xml中的配置
<!—控制器  在Sprint web Libraries包下 ,sprint-struts.jar下,strurs包中-->
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
   </controller>

三:在applicationContext.xml中的配置

<!—事物  在spring Persistence包下,spring-Hibernate包下,orm.hibenate包里-->
<bean
id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <property name="sessionFactory">
        <ref bean="sessionFactory"/>
    </property>
</bean>

<tx:advice id="txAdvice">
     <tx:attributes>
         <tx:method name="find" read-only="true"/>
         <tx:method name="search" read-only="true"/>
         <tx:method name="*"/>
     </tx:attributes>
</tx:advice>

<aop:config>
    <aop:advisor advice-ref="txAdvice"
                 pointcut="execution(* com.svse.service.*Service.*(..))"/>
</aop:config>

猜你喜欢

转载自zsqfengchen.iteye.com/blog/1092692