mybatis 整合spring之mapperLocations配置的问题(转)
以防忘记,收集一下别人的文章吧
https://www.cnblogs.com/1xin1yi/p/7373739.html
今天尝试spring整合mybatis时遇到这么一个问题,就是在配置sqlSessionFactory时是否要配置mapperLocations的问题。

<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="datasource"></property>
<property name="typeAliasesPackage" value="com.fan.entity"/>
<!-- 当mybatis的xml文件和mapper接口不在相同包下时,需要用mapperLocations属性指定xml文件的路径。
*是个通配符,代表所有的文件,**代表所有目录下 -->
<property name="mapperLocations" value="classpath:com/fan/mapper/*.xml" /> <!--也可以引入mybatis配置文件
<property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"></property> -->
</bean>
<!-- 通过扫描的模式,扫描目录在com.lanyuan.mapper目录下的mapper-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.fan.mapper"></property>
</bean>

结论是:如果Mapper.xml与Mapper.class在同一个包下且同名,spring扫描Mapper.class的同时会自动扫描同名的Mapper.xml并装配到Mapper.class。
如果Mapper.xml与Mapper.class不在同一个包下或者不同名,就必须使用配置mapperLocations指定mapper.xml的位置。
此时spring是通过识别mapper.xml中的 <mapper namespace="com.fan.mapper.UserDao"> namespace的值来确定对应的Mapper.class的。
mybatis 整合spring之mapperLocations配置的问题(转)的更多相关文章
- mybatis 整合spring之mapperLocations配置的问题
今天尝试spring整合mybatis时遇到这么一个问题,就是在配置sqlSessionFactory时是否要配置mapperLocations的问题. <bean id="sessi ...
- mybatis整合spring的时候配置数据库信息文件properties注意事项
信息后面不能有空格 ,格式要xxx.driver xxx.url 这样
- 不需要怎么修改配置的Mybatis整合Spring要点
首先对于Mybatis的主配置文件,只需要修改一处地方,将事务交给Spring管理,其它地方可以原封不动. <?xml version="1.0" encoding=&quo ...
- Mybatis整合Spring -- typeAliasesPackage
Mybatis整合Spring 根据官方的说法,在ibatis3,也就是Mybatis3问世之前,Spring3的开发工作就已经完成了,所以Spring3中还是没有对Mybatis3的支持. 因此由M ...
- 160330、Mybatis整合Spring
转自csdn文章 http://haohaoxuexi.iteye.com/blog/1843309 Mybatis整合Spring 根据官方的说法,在ibatis3,也就是Mybatis3问世之前, ...
- mybatis整合Spring编码
mybatis整合Spring的核心代码 spring-dao.xml <?xml version="1.0" encoding="UTF-8"?> ...
- mybatis整合spring 之 基于接口映射的多对一关系
转载自:http://my.oschina.net/huangcongmin12/blog/83731 mybatis整合spring 之 基于接口映射的多对一关系. 项目用到俩个表,即studen ...
- mybatis整合spring获取配置文件信息出错
描述:mybatis整合spring加载jdbc.properties文件,然后使用里面配置的值来 配置数据源,后来发现用户变成了admin- jdbc.properties的配置: 加载配置: 报错 ...
- JAVAEE——Mybatis第二天:输入和输出映射、动态sql、关联查询、Mybatis整合spring、Mybatis逆向工程
1. 学习计划 1.输入映射和输出映射 a) 输入参数映射 b) 返回值映射 2.动态sql a) If标签 b) Where标签 c) Sql片段 d) Foreach标签 3.关联查询 a) 一对 ...
随机推荐
- oracle 11g(64位)datebase 安装流程
软件版本:oracle 11g 64位 datebase(二合一,含client) 系统环境:windows 10 专业版 64位操作系统 1)根据自己的操作系统去官网下载相应的安装程序,oracle ...
- Linux 命令的20个实用范例,入门必看!
Tips: 达内Linux云计算免费课程火热抢报中,点击文末“阅读原文”快速抢! Linux中一个基本命令是ls.没有这个命令,我们会在浏览目录条目时会遇到困难.这个命令必须被每个学习Linux的人知 ...
- LeetCode - Rectangle Overlap
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
- 【BZOJ1202】【HNOI2005】狡猾的商人
查分约束好,好写好调好AC! 原题: 刁姹接到一个任务,为税务部门调查一位商人的账本,看看账本是不是伪造的.账本上记录了n个月以来的收入情况,其中第i 个月的收入额为Ai(i=1,2,3...n-1, ...
- openresty router && template 试用
router 是一个比较方便的 openresty 路由组件,我们可以用来编写灵活强大的 web 应用,类似的 lua-resty-route 也是很不错的,但是如果是比较简单的直接可以使用 lu ...
- The dis/advantage of forward declaration
In our projects, in C++ head file, if reference to some classes (reference or pointer), instead of i ...
- java_架构与模式
框架有哪些?C++语言的QT.MFC.gtk,Java语言的SSH,php语言的 smarty(MVC模式),python语言的django(MTV模式)等等设计模式有哪些?工厂模式.适配器模式.策略 ...
- 线性代数笔记10——矩阵的LU分解
在线性代数中, LU分解(LU Decomposition)是矩阵分解的一种,可以将一个矩阵分解为一个单位下三角矩阵和一个上三角矩阵的乘积(有时是它们和一个置换矩阵的乘积).LU分解主要应用在数值分析 ...
- sql server 用户创建与权限管理
要想成功访问 SQL Server 数据库中的数据, 我们需要两个方面的授权:一.获得准许连接 SQL Server 服务器的权利: 二.获得访问特定数据库中数据的权利(select, update, ...
- hbase java 基本例子
一下代码实用 0.99.0 以后的版本. package hadoop; import java.io.IOException; import java.util.ArrayList; import ...