SSH整合

 使用annotcontion编写配置文件:

<!-- 在web.xml 中配置Spring配置 的文件 -->

<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>classpath:applicationContext-*.xml</param-value>
 <!-- <param-value>/WEB-INF/applicationContext-*.xml</param-value>  -->
</context-param>
 
<listener>
  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 请求数据的编码过滤器 -->
 <filter>
  <filter-name>charsetFilter</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>
 </filter>
 <filter-mapping>
  <filter-name>charsetFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

<!-- OSIV -->
 <filter>
  <filter-name>osiv</filter-name>
  <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
 </filter>
 <filter-mapping>
  <filter-name>osiv</filter-name>
  <url-pattern>*.do</url-pattern>
 </filter-mapping>

<!-- 在struts-config.xml中配置 -->

 <!-- 使用Spring的请求处理器 -->
    <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>

<!-- 在applicationConfig-dao.xml -->

 <!-- C3P0连接池 -->
 <bean id="dataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource">
  <property name="driverClass" value="com.mysql.jdbc.Driver" />
  <property name="jdbcUrl" value="jdbc:mysql:///test" />
  <property name="user" value="root" />
  <property name="password" value="root" />
 </bean>
 
 <!-- sessionFactory -->
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="configLocation" value="classpath:hibernate.cfg.xml" />
  <property name="dataSource" ref="dataSource"/>
 </bean>
 
 <!-- Dao配置 -->
 <bean id="daoParent" class="com.liuc.dao.impl.GenericDaoImpl" abstract="true">
  <property name="sessionFactory" ref="sessionFactory"/>
 </bean>
 
 <!-- 这里添加每个Dao的配置 -->
 <bean name="accountDao" class="com.liuc.dao.impl.AccountDaoImpl" parent="daoParent" />

<!--在applicationService.xml中配置 -->

 <!-- 声明式事务 -->
 <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="*" isolation="READ_COMMITTED"/>
   <tx:method name="find*" read-only="true"/>
  </tx:attributes>
 </tx:advice>
 <aop:config>
  <aop:advisor advice-ref="txAdvice" pointcut="execution(* com.liuc.service.impl.*.*(..))"/>
 </aop:config>
 
 <!-- 这里添加业务逻辑类的配置 -->
 <bean name="serviceFacade" class="com.liuc.service.impl.ServiceFacadeImpl" abstract="true" >
   <property name="accountDao " ref="accountDao"/>
   <property name="categoryDao" ref="cagegoryDao" />
 </bean>

注:    <property name="accountDao " ref="accountDao "/> 中的 name=" accountDao " 一定要与ServiceFacadeImpl中的属性相同, ref="accountDao"一定要与dao层中的 <bean name="accountDao " class="com.liuc.dao.impl.AccountDaoImpl" parent="daoParent" />相同

<!-- 在applicationConfig-web.xml中配置>

 <!-- 配置Struts1的Action类 -->
 <bean id="actionParent" class="com.liuc.web.action.BaseAction" abstract="true">
  <property name="serviceFacade" ref="serviceFacade"/>
 </bean>
 
 <!-- 这里针对struts-config.xml中的每个Action配置对应别名的Bean -->
    <bean name="/login" class="com.liuc.web.action.BaseAction" parent="actionParent"></bean>

原文地址:https://www.cnblogs.com/java20130726/p/3218462.html