MyBatis-Spring 之SqlSessionFactoryBean
2024-09-01 13:42:34
要创建工厂 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 文
最新文章
- 慕课网__CSS__vertical align
- TypeError: coercing to Unicode: need string or buffer, ChatRoom found
- CF 268E Playlist(贪心)
- T 泛型转换
- 自用有线IP切换
- Java基础知识强化之IO流笔记43:IO流练习之 复制文本文件的 5 种方式案例
- POJ1664
- MySQL 元数据
- HDOJ 1303 Doubles(简单题)
- 【夸QT在十五】ctkPluginFrameWork插件系统Windows编译器
- ER模型
- JS基础——循环很重要
- linux下的清屏命令
- 理解WebKit和Chromium: Web应用和Web运行环境
- AI学习---深度学习&;TensorFlow安装
- android 使用opencv
- (1.11)SQL优化——mysql提示(hint)
- (转)android:inputType参数类型说明
- Android——开源框架Universal-Image-Loader + Fragment使用+轮播广告
- 报错:具有键";...";的ViewData项属于类型";...";,但它必须属于类型";IEnumerable<;SelectListItem>;";