要创建工厂 bean,放置下面的代码在 Spring 的 XML 配置文件中:

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

  <property name="dataSource" ref="dataSource"/>

</bean>

要注意SqlSessionFactoryBean 实现了Spring 的FactoryBean 接口(请参考 Spring 文档的这就说明了由 Spring 最终创建的 bean 不是 SqlSessionFactoryBean 本身。而是工厂类的 getObject()返回的方法的结果。SqlSessionFactory 有一个单独的必须属性,就是 JDBC 的 DataSource。

mapperLocations 属性使用一个资源位置的 list。 这个属性可以用来指定 MyBatis 的 XML 映射器文件的位置。 它的值可以包含 Ant 样式来加载一个目录中所有文件, 或者从基路径下 递归搜索所有路径

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" value="classpath*:sample/config/mappers/**/*.xml" />
</bean>

这会从类路径下加载在 sample.config.mappers 包和它的子包中所有的 MyBatis 映射器 XML 文

最新文章

  1. 慕课网__CSS__vertical align
  2. TypeError: coercing to Unicode: need string or buffer, ChatRoom found
  3. CF 268E Playlist(贪心)
  4. T 泛型转换
  5. 自用有线IP切换
  6. Java基础知识强化之IO流笔记43:IO流练习之 复制文本文件的 5 种方式案例
  7. POJ1664
  8. MySQL 元数据
  9. HDOJ 1303 Doubles(简单题)
  10. 【夸QT在十五】ctkPluginFrameWork插件系统Windows编译器
  11. ER模型
  12. JS基础——循环很重要
  13. linux下的清屏命令
  14. 理解WebKit和Chromium: Web应用和Web运行环境
  15. AI学习---深度学习&amp;TensorFlow安装
  16. android 使用opencv
  17. (1.11)SQL优化——mysql提示(hint)
  18. (转)android:inputType参数类型说明
  19. Android——开源框架Universal-Image-Loader + Fragment使用+轮播广告
  20. 报错:具有键&quot;...&quot;的ViewData项属于类型&quot;...&quot;,但它必须属于类型&quot;IEnumerable&lt;SelectListItem&gt;&quot;

热门文章

  1. @Component默认是单例还是多例?
  2. java读取request中的xml
  3. SpringMvc+ajax跨域请求时,出现options类型的请求并返回403的解决方案
  4. linux lnmp下无法使用mail发邮件的两种解决方法
  5. 做了一个非竞价排名、有较详细信息的程序员职位 match 网站
  6. leetcode1140 Stone Game II
  7. windows下进程与线程
  8. MyBatis框架总结
  9. CardView的使用(可以实现圆角控件)
  10. extentreports报告插件与testng集成