maven spring mybatis配置注意点
以下对使用maven配置spring+mybatis项目时,完成基本的配置需要添加的一些信息进行说明。仅对mybatis部分进行列举。
- maven添加mybatis支持
<!-- mybatis核心包 –>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.2.2</version>
</dependency>
<!-- mybatis/spring包 -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.2.2</version>
</dependency>
- 建立配置文件
1、在java resource文件夹下建立一个新的source folder,新建一个package,或者拷贝一个package过来,在该class下建立实体的mapper文件,本例中为StudentDAO.xml
2、在config文件中建立mybatis的配置文件,包含mapper文件,
configuration的内容如下:
<configuration>
<mappers>
<mapper resource="com/tutorialspoint/StudentDAO.xml"/>
</mappers>
</configuration>
本方法建立好后的路径格式如下

- 在spring配置文件中配置mybatis的映射关系
在已有spring配置文件中添加如下内容
<bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis-config.xml" />
</bean>
<!-- 自动扫描了所有的XxxxMapper.xml对应的mapper接口文件不用一个一个手动配置Mpper的映射 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.tutorialspoint" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean"></property>
</bean>
<bean id="studentDAO" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="com.tutorialspoint.StudentDAO"></property>
<property name="sqlSessionFactory" ref="sqlSessionFactoryBean" />
</bean>注意不要修改property name关键字名称
配置过程中最容易出错的是路径配置,包含文件时尽可能遵循规范的做法,将配置文件放置在package中,便于spring配置可以找到其他的配置文件。
其他博客中将会对配置文件的各个标签含义进行具体解释。
maven spring mybatis配置注意点的更多相关文章
- Eclipse Maven Spring MyBatis 配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://mave ...
- maven,spring,mybatis集成错误
maven,spring,mybatis集成的时候单元测试junit测试没问题,但mvn jetty:run 就报错误 错误: org.apache.ibatis.binding.BindingExc ...
- mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(附demo和搭建过程遇到的问题解决方法)
文章介绍结构一览 一.使用maven创建web项目 1.新建maven项目 2.修改jre版本 3.修改Project Facts,生成WebContent文件夾 4.将WebContent下的两个文 ...
- mybatis学习笔记(六) -- maven+spring+mybatis从零开始搭建整合详细过程(下)
继续 mybatis学习笔记(五) -- maven+spring+mybatis从零开始搭建整合详细过程(上) 五.使用监听器启动Spring容器 1.修改pom.xml文件,添加Spring-we ...
- Spring+Mybatis配置
Spring+Mybatis配置 之前做项目的时候用到了spring+mybatis框架,一直想抽空整理一下 Mybatis: mybatis是支持普通 SQL查询,存储过程和高级映射的优秀持久层框架 ...
- spring+myBatis 配置多数据源,切换数据源
注:本文来源于 tianzhiwuqis <spring+myBatis 配置多数据源,切换数据源> 一个项目里一般情况下只会使用到一个数据库,但有的需求是要显示其他数据库的内容,像这样 ...
- 框架基础学习之--详解web+maven+spring+mybatis+struts框架文件夹作用
详解web+maven+spring+mybatis+struts框架文件夹作用 1.程序名 2.Mybatis,mybatis是数据持久层,就是和对象类有关系的东西 3.存放java文件,xml,p ...
- Maven + spring + Mybatis + SpringMVC
tomcat版本:apache-tomcat-7.0.70 一.新建一个maven的web项目 1.1.请勾选“Create a simple project”,创建一个简单的项目,这里不使用模板.也 ...
- Maven+Spring MVC Spring Mybatis配置
环境: Eclipse Neon JDK1.8.0 Tomcat8.0 先决条件: Eclipse先用maven向导创建web工程.参见本站之前随笔. 本机安装完成mysql5:新建用户xuxy03设 ...
随机推荐
- JavaScript 格式化时间
//格式化 yyyy-MM-dd hh:mm:ss function renderTime(date) { if (date == '' || date == null) { return ''; } ...
- DOM 以及JS中的事件
[DOM树节点] DOM节点分为三大节点:元素节点,文本节点,属性节点. 文本节点,属性节点为元素节点的两个子节点通过getElment系列方法,可以去到元素节点 [查看节点] 1 document. ...
- HDU 5008 求第k小子串
本题要求第k小的distinct子串,可以根据height数组,二分出这个第k小子串所在后缀的位置信息.由于题目要求子串起始下标尽可能小.所以再在rank数组中,二分出与当前后缀LCP大于等于所求子串 ...
- Google Earth影像数据破解之旅
"Zed, you are so excellent." 为什么要写这句英文?容我卖个关子稍后再解释. 相信大多数人都体验过Google Earth(简称GE),我对GE最初的印象 ...
- 第三章 Docker的镜像
3.1.获取镜像 获取镜像 docker pull name[:TAG] #默认是从网络下载镜像,不指定tag会人下载latest标签下的镜像. 1 2 docker search ubuntu do ...
- 解析http协议的url
package util; import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamRea ...
- bzoj3939 【USACO 2015 FEB GOLD 】cow hopscotch
Description 就像人类喜欢玩"跳房子"的游戏,农民约翰的奶牛已经发明了该游戏的一个变种自己玩.由于笨拙的动物体重近一吨打,牛跳房子几乎总是以灾难告终,但这是没有阻止奶牛几 ...
- 蓝桥杯-奇怪的分式-java
/* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2016, 广州科技贸易职业学院信息工程系学生 * All rights reserved. * 文件名称: ...
- Gym - 101102C线段树
Judge Bahosain was bored at ACM AmrahCPC 2016 as the winner of the contest had the first rank from t ...
- phtread_mutex 组合
phtread_mutex通过mutexattr设定其类型,并保存在成员__kind中.pthread_mutex的锁操作函数根据__kind进行方法的分派(dispatch).__kind由5个字段 ...