Spring3 +mybatis3 之 MapperScannerConfigurer
之前一直使用"org.mybatis.spring.mapper.MapperFactoryBean"这个类在spring中配置mybatis的dao接口,后来发现如果dao太多话,配置非常繁冗,于是想改用
org.mybatis.spring.mapper.MapperScannerConfigurer来精简配置.
使用注意, 直接上代码吧:
1. dao的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
<!-- 一定得指定这个属性!--> default-autowire="byType"
>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"/>
<property name="mapperLocations" value="classpath:mybatis/mapper/*.xml"/>
</bean>
<!-- 无需指定其他属性 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- value是dao接口类所处的package-->
<property name="basePackage" value="com.jd.jd_ptesting.dao" />
</bean>
</beans>
2. Service 配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
default-autowire="byType"
>
<bean id="settingService" class="com.jd.jd_ptesting.service.impl.SettingServiceImpl">
<!-- 注意 此处一定不要指定dao属性!!!
<property name="settingDao" ref="settingDao" />
-->
</bean> </beans>
Spring3 +mybatis3 之 MapperScannerConfigurer的更多相关文章
- Spring3+Mybatis3+Mysql+ivy+liquibase
Spring3+Mybatis3+Mysql+ivy+liquibase 集成 近一周时间所学技术:整合Spring+MyBatis+MySql+ivy+liquibase Mybatis:是一个基于 ...
- struts2 + spring3 + mybatis3 环境搭建
struts2 + spring3 + mybatis3 1. 框架下载 struts2: http://struts.apache.org/ 下载 struts-2.3.14-all.zip spr ...
- Struts2+Spring3+Mybatis3开发环境搭建
本文主要介绍Struts2+Spring3+Mybatis3开发环境搭建 Struts和Spring不过多介绍. MyBatis 是支持普通 SQL 查询,存储过程和高级映射的优秀持久层框架.MyBa ...
- Spring3+MyBatis3整合log4j无法输出SQL语句问题的解决
今天遇到了跟下面文章一模一样的问题,下面文章的解决方案很好,在这里记录保存一下. Spring3+MyBatis3整合无法输出SQL语句问题的解决
- Spring3+mybatis3在多数据源情况下找不到数据库驱动的问题
解决问题的过程如下: 1.遇到问题和一般的解决方法和下面这个帖子的一样: http://www.oschina.net/question/188964_32305 2.我在按照1的做法配置了以后,依然 ...
- Struts2+Spring3+MyBatis3整合以及Spring注解开发
分类: Web(2) 版权声明:本文为博主原创文章,未经博主允许不得转载. 最近在做一个SpringMVC+spring+MyBatis的项目,突然想起以前自己要搭建一个Struts2+Sprin ...
- jsp fmt页面显示value does not support runtime expressions
最近使用Struts2+Spring3+Mybatis3做一个项目,在用户修改页面显示生日, <fmt:formatDate value="${user.birthday}" ...
- ssmWeb开发框架_2014-01
一直在准备做一套系统, 具体用来干什么都没确定. 只是从纯技术人员的想法, 先搭建一套开发的框架. 做的时候才发现, 系统用途不同, 框架也是不同的. 暂时就先当作企业内部管理的系统来做吧. 后台基础 ...
- Dubbo入门到精通学习笔记(一):Dubbo对传统工程进行改造、注册中心安装(Zookeeper-3.4.6)、工程结构优化
文章目录 改造思路 样例工程:传统的单工程项目(edu-demo) 模型结构 思路 改成dubbo调用方式后的工程结构 部署环境规划 改造 愚公移山 迁移包 迁移页面: 迁移配置相关 新项目的主要作用 ...
随机推荐
- JAXB - XML Schema Types, Defining Subtypes
Although object orientation isn't a key feature of XML or the XML Schema language, it's still possib ...
- Spring的servlet context和application context
Spring lets you define multiple contexts in a parent-child hierarchy. The applicationContext.xml def ...
- listview使用checkbox批量删除出现的问题
1.选中前面的checkbox导致后的checkbox被选中 2.选中后下滑listview,再上滑时被选中的checkbox又变成未选中状态. 问题大都是因为对listview进行代码优化重用con ...
- THP Transparent HugePages关闭
ambari 安装Hortonworks HDP 时在检测host异常 The following hosts have Transparent Huge Pages (THP) enabled.TH ...
- ubuntu下aircrack-ng的wifi破解
首先安装aircrack-ng,apt-get install aircrack-ng. 然后打开shell,输入airmon-ng start wlan0. 输入airodump-ng mon0. ...
- 【小丸类库系列】Excel操作类
using Microsoft.Office.Interop.Excel; using System; using System.IO; using System.Reflection; namesp ...
- windows下vs2013使用C++访问redis
刚开始在windows下使用c++访问reids各种报错,经过网上到处搜方案,终于可以在windows下访问redis了,特将注意事项记录下来: 1.获取redis Window下的开发库源码,从gi ...
- 关于使用工具类org.apache.commons.collections.ListUtils合并List的问题
今天在做项目时,需要将几个List进行合并,于是就用到了apache提供关于List操作的工具类ListUtils,但是在使用的过程中发现一些问题. public static void main(S ...
- mysql 的rmp安装
新文档/* GitHub stylesheet for MarkdownPad (http://markdownpad.com) *//* Author: Nicolas Hery - http:// ...
- jquery ajax php+mysql 无刷新分页 详细实例
最近在接触jquery和ajax,当前项目也会用到分页,为了用户体验更好一些,就准备用无刷新分页,这个demo很适合新手学习查看,写的比较清晰,话不多说,直接上代码吧. 首先是html页面,index ...