一、spring+struts:
1、导入入struts+spring整合需要的jar文件(struts2-spring-plugin-2.3.1.2)
2、配置web.xml
<!-- 配置struts -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置spring,如果在web-inf下可以只要listener-->
<context-param>
<param-name>contextConfigLocation</param-name><!-- contextConfigLocation 名不能改变化 -->
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
3、配置struts文件
<action name="user_*" class="userAction" method="{1}"> //即为struts的action前加上注解
二、spring+struts+hibernate:
1.在web.xml中通过ContextLoaderListener来融入spring,并加载spring的相关配置文件
2.配置sturts2的前端总控制器filterDispatcher来过滤相关的请求并且加载struts.xml
3.action继承ActionSupport,然后通过引入struts-spring-plugin.jar包并且根据配置文件中service的id生成get,set方法来注入service层。
4.dao层继承于HibernateDaoSupport,并且在dao的配置文件中注入sessionFactory.也可直接使用HibernateTemplate
5.spring中的配置文件加载hibernate.cfg.xml文件从而融入hibernate.
<listener>
<description>Spring core configuration</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
三、spring+spring mvc+mybatis:
1、导入框架所需的jar包
2、配置web.xml--->加入spring、spring mvc和解决乱 码的配置文件
3、配置spring-->applicationContext.xml
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage">
<value>com.hy.mapperdao</value>
</property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- spring配置事务 基于注解开发 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 纯注解方式,只需要所需类前加上 @Transactional -->
<tx:annotation-driven transaction-manager="transactionManager" />
4、开发entity-->dao接口-->mapper.xml(要求id的名和接口中的方法名一致),不需要开发实现接口