整合时除了未整合前spring、mybatis的必须包外还需要加入两个包

spring-jdbc-4.2.5.RELEASE.jar

mybatis-spring-1.2.5.jar

spring-jdbc-4.2.5.RELEASE.jar 提供了Mybatis所用数据源的管理

mybatis-spring-1.2.5.jar 提供了myBatis所用的sqlSessionFactionBean 和SqlSessionTemplate

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- 自动装配配置 -->
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />
<!-- 数据源Bean配置 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/appproject" />
<property name="username" value="root" />
<property name="password" value="12345678" />
</bean>
<!-- MyBatis session工厂bean配置 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="mapperLocations" value="classpath*:mappers/mapper-*.xml"></property>
</bean>
<!-- 创建session bean,自动装配 -->
<bean class="org.mybatis.spring.SqlSessionTemplate" autowire="byType">
<constructor-arg ref="sqlSessionFactory"></constructor-arg>
</bean>
<import resource="beans-dao.xml" />
<import resource="beans-service.xml" /> </beans>
org.springframework.jdbc.datasource.DriverManagerDataSource类是spring-jdbc提供的数据源对象,我们创建SqlSessionTemplate时用的是这个类的构造方法,传入的参数的类型是SqlSessionFactionBean,这个Bean是由mybatis-spring提供的。
SqlSessionTemplate使用了自动装配的方式(代码如下),我的Dao层有一个基类,基类中的SqlSessionTemplate 已经用@Autowired。Spring启动时,会自动注入,想要了解自动装配的方式请点击我的另外一篇博客@Autowired的使用
public class BaseDao {
@Autowired
protected SqlSessionTemplate session;
}

当然,整合的方式有很多种,此处是其中之一。

最新文章

  1. .Net多线程编程—任务Task
  2. osi(open system interconnection)模型的通俗理解
  3. SQL转换时间的时分
  4. angularjs 自定义服务的三种方式
  5. WireShark网络性能分析
  6. 鼠标滑动加载div
  7. 理解RESTful架构(转载)
  8. shellcode流程
  9. android中getSystemService详解
  10. django form关于clean及cleaned_data的说明 以及4种初始化
  11. &quot;最大工作进程数&quot;导致的WCF调用失败
  12. webservice的调用方法
  13. Bootstrap table使用心得---thead与td无法对齐的问题
  14. Javascript Sting(字符串)对象
  15. Java基本数据类型和长度
  16. 修改Linux主机名
  17. net.sf.json
  18. winfrom里面打印类似小票
  19. Linux下清理内存和Cache方法
  20. 网络请求Adapter添加数据

热门文章

  1. 一位同事对 Rafy 框架的一些建议及我的回复
  2. WPF入门:XAML
  3. python学习笔记(基础二:注释、用户输入、格式化输出)
  4. Linux安装jdk
  5. python generator next send
  6. 子div设置浮动无法把父div撑开。
  7. 重新诠释的OSGi规范
  8. Office 365使用情况调查不完全分析报告
  9. T-SQL 去除特定字段的前导0
  10. JS巧妙思路