Spring配置iBatis多个SqlMapConfig.xml
Spring粘合iBatis的时候需要配置iBatis的SqlMapConfig.xml
对于项目多个模块而又想同时能管理起来,普遍的单个SqlMapConfig.xml就会显得臃肿
可喜的是Spring已经为大家想好这一切,提供能灵活的配置
configLocation // 单个SqlMapConfig.xml
configLocations // 多个SqlMapConfig.xml
mappingLocations // 自动匹配SqlMapConfig.xml
假设现在有几个配置文件,分别存放在不同的目录,结构如下
classes
|----SqlMapConfig.xml
|----com.xxx
|----aModule
| |----A-SqlMapConfig.xml
|----BModule
|----B-SqlMapConfig.xml
现在通过Spring配置以上几个SqlMapConfig.xml
- <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
- <!-- 1. 配置单个SqlMapConfig.xml, 使用configLocation属性-->
- <property name="configLocation" value="classpath:SqlMapConfig.xml"/>
- <!-- 2. 配置多个SqlMapConfig.xml, 使用configLocations属性-->
- <!-- 不包含class目录下的SqlMapConfig.xml -->
- <property name="configLocations">
- <list>
- <value>classpath:com/xxx/a/A-SqlMapConfig.xml</value>
- <value>classpath:com/xxx/b/B-SqlMapConfig.xml</value>
- </list>
- </properties>
- <!-- 3. 匹配多个SqlMapConfig.xml, 使用mappingLocation属性-->
- <!-- 不包含class目录下的SqlMapConfig.xml -->
- <property name="mappingLocation" value="classpath:com/xxx/*/*-SqlMapConfig.xml"/>
- <!-- 其他配置,例如dataSource等等 -->
- <property name="dataSource" ref="dataSource"/>
- </bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<!-- 1. 配置单个SqlMapConfig.xml, 使用configLocation属性-->
<property name="configLocation" value="classpath:SqlMapConfig.xml"/>
<!-- 2. 配置多个SqlMapConfig.xml, 使用configLocations属性-->
<!-- 不包含class目录下的SqlMapConfig.xml -->
<property name="configLocations">
<list>
<value>classpath:com/xxx/a/A-SqlMapConfig.xml</value>
<value>classpath:com/xxx/b/B-SqlMapConfig.xml</value>
</list>
</properties>
<!-- 3. 匹配多个SqlMapConfig.xml, 使用mappingLocation属性-->
<!-- 不包含class目录下的SqlMapConfig.xml -->
<property name="mappingLocation" value="classpath:com/xxx/*/*-SqlMapConfig.xml"/>
<!-- 其他配置,例如dataSource等等 -->
<property name="dataSource" ref="dataSource"/>
</bean>
这样,Spring就解决了多个模块下不同模块之前独立配置sqlMapConfog.xml的问题了。这个Spring2.5.5以后才支持
iBatis也能解决这类问题,不过要是iBatis高版本才支持,因为我使用的是2.3的,这方面就没有验证了
- <?xml version="1.0" encoding="UTF-8"?>
- <sqlMapConfig>
- <!-- <sqlMapImport resource="" url=""/> -->
- <sqlMapImport resource="com/xxx/a/A-SqlMapConfig.xml"/>
- <sqlMapImport resource="com/xxx/b/B-SqlMapConfig.xml"/>
- </sqlMapConfig>
Spring配置iBatis多个SqlMapConfig.xml相关推荐
- 02_MyBatis项目结构,所需jar包,ehcache.xml配置,log4j.properties,sqlMapConfig.xml配置,SqlMapGenerator.xml配置
项目结构(所需jar包,配置文件) sqlMapConfig.xml的配置内容如下: <?xmlversion="1.0"encoding="UTF-8&qu ...
- spring 配置相关
1.spring配置相关 初始化配置文件 web.xml <context-param> <param-name>contextConfigLocation&l ...
- Spring Boot整合MyBatis框架(XML文件版)
1.创建数据库.数据库表并插入数据 创建数据库springboot: CREATE DATABASE springboot; 创建数据库表user: CREATE TABLE `user` (`id` ...
- ibatis之——sqlMapConfig.xml配置文件详解
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/47104893 sqlMapConfig.xml配置文件详解: <?xml v ...
- Mybatis mapper代理SqlMapConfig.xml配置详解
SqlMapConfig.xml是mybatis的全局配置文件: 1.mapper映射配置 >配置mapper的另外一种方式: <mappers> <mapper resour ...
- mybatis配置 SqlMapConfig.xml user.xml
一.SqlMapConfig.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE co ...
- 【MyBatis学习05】SqlMapConfig.xml文件中的配置总结
经过上两篇博文的总结,对mybatis中的dao开发方法和流程基本掌握了,这一节主要来总结一下mybatis中的全局配置文件SqlMapConfig.xml在开发中的一些常用配置,首先看一下该全局配置 ...
- spring boot分环境导出自定义xml配置
背景介绍: 由于新的spring boot项目需要使用老的jar包,老的jar包的配置是用xml方式配置的,而且开发development.测试test.集成off.正式production环境都会有 ...
- Spring boot 集成工作流flowable去掉xml配置
工作流Flowable和Spring集成时,有一个xml是用来配置ProcessEngine的信息,xml的内容如下所示: <?xml version="1.0" encod ...
最新文章
- [转]DPM2012系列之四:配置邮件报警功能
- 【mybatis】mybatis中 的# 和 $的区别
- 【高级Java架构师系统学习】java十六进制字符串转数字
- Android5.0新特性:主题样式
- pwn(ctf)中常见的系统调用
- 【Python】Pandas/Sklearn进行机器学习之特征筛选,有效提升模型性能
- GraphQL报错:error: NetworkError when attempting to fetch resource.
- python多任务笔记
- Opencv Mat CascadeClassifier cstdio
- [二叉树遍历|BST]leetcode 538 把二叉搜索树转换为累加树
- 修改 win10 的 CMD 控制台字体
- Atitit 图像处理Depixelizing Pixel Art像素风格画的矢量化
- Jquery cookies 记忆菜单
- 一周信创舆情观察(11.16~11.22)
- 【大学物理·光学】圆孔的夫琅禾费衍射光学仪器的分辨本领
- 量子电动力学和量子场论,多体系统的量子场论
- 【知识图谱】OpenKG 发布多个新冠病毒相关开放知识图谱
- html5 制作游戏
- iOS framework动态库重签名
- WordPress主题 Market 多用途,灵活,类似(ThemeForest)高级数码交易市场主题
热门文章
- [机器学习] Coursera ML笔记 - 逻辑回归(Logistic Regression)
- 妇女在IT安全工作人员当中的比例只有10%
- org.hibernate.AnnotationException: No identifier specified for entity
- python字符串和字典
- 【NOI2015】荷马史诗
- requests与urllib.request
- 软件工程学习笔记——软件工程基本原理
- Redis学习(2)-redis安装
- win10 1709电脑无法显示局域网共享
- Python进阶之一