1.在maven下,至于需要的架包,地址入右;http://blog.csdn.net/m0_37942145/article/details/63253566
2.web.xml中的相关配置,struts2负责前端请求拦截,Spring负责bean的实例,mybatis负责数据库的操作
具体的数据库操作在applicationContext.xml中
<filter>
<filter-name>struts2</filter-name>
<filter-class> org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
<!-- 自从Struts 2.1.3以后,下面的FilterDispatcher已经标注为过时
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> -->
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- applicationContext.xml -->
<!-- Spring监听器 会自动查找WEB-INF下的applicationContext.xml文件 -->
<listener>
<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>
3.以下是具体的applicationContext.xml的相关配置
<!-- 配置自动扫描器 -->
<context:component-scan base-package="com"></context:component-scan>
<!-- 自动代理类 -->//关于SpringAop切面的
<aop:aspectj-autoproxy ></aop:aspectj-autoproxy>
<!-- 注册jdbc.properties方法 2种:context方式注册-->
<context:property-placeholder location="classpath:jdbc.properties"/>//关于jdbc.properties没写很简单
<!-- 数据源配置:可以C3p0-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driver}"></property>
<property name="jdbcUrl" value="${url}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean>
<!--2 JDBC模版注入 C3p0要用的模板
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>
-->
<!--
在 MyBatis 中,使用 SqlSessionFactoryBuilder创建SqlSessionFactory ,进而来创建 SqlSession。
得到 session 之后,你可以使用它来执行映射语句,提交或回滚连接,最后,当不再需要它的时候, 你可以关闭 session。
Mybatis社区自己开发了一个Mybatis-spring用来满足Mybatis用户整合Spring的需求。
使用 MyBatis-Spring 之后, 会使用SqlSessionFactoryBean来代替SqlSessionFactoryBuilder创建SqlSessionFactory,
然后可以使用使用sqlSession。
Mybatis-Spring提供了一种直接使用SqlSession的方式(一个实现了SqlSession接口的SqlSessionTemplate实现类)
它是线程安全的,可以被多个Dao同时使用;
它跟Spring的事务进行了关联,确保当前被使用的SqlSession是一个已经和Spring的事务进行绑定了的,而且它还可以自己管理Session的提交和关闭
-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据源的获取 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 得到mybatis的核心配置文件
<property name="configLocation" value="classpath:mybatis.xml"/>
-->
<!-- 自动扫描mapping.xml文件,**表示迭代查找 代替了 config -->
<property name="mapperLocations" value="classpath:com/bean/**/*.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sqlSessionFactory"></constructor-arg>
</bean>
4.struts.xml的相关配置,就不多说,很简单;
5.至于具体的分层是典型的mvc架构,就不多说,bean,service,dao,web,典型的分层
6,至于完整的源码如有边所示点击打开链接