spring和mybatis整合配置

<?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"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!--开启自动扫描  -->
<context:component-scan base-package="com.pb.zte"/>
<!--引入JDBC配置文件  -->
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:jdbc.properties"/>
</bean>
<!--数据源  -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<!--驱动  -->
<property name="driverClassName" value="${driver}"/>
<!--URL  -->
<property name="url" value="${url}"/>
<!--username  -->
<property name="username" value="${username}"/>
<!--password  -->
<property name="password" value="${password}"/>
</bean>
<!--sqlSessionFactory  spring和MyBatis完美整合,不需要mybatis的配置映射文件-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据源  -->
<property name="dataSource" ref="dataSource"/>
<!--扫描所有Dao的实现类xml 自动扫描mapping.xml文件-->
<property name="mapperLocations" value="classpath:com/pb/zte/mapping/*.xml"/>
</bean>
<!--为所有DAO层注入sqlSessionFactory  -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--基本包Dao层所在包最上一层  -->
<property name="basePackage" value="com.pb.zte.mapper"/>
<!--注入sqlSessionFactoryBeanName  -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>

<!--数据源事务管理  -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!--注入数据源  -->
<property name="dataSource" ref="dataSource"/>
</bean>

</beans>
时间: 2024-08-07 00:17:07

spring和mybatis整合配置的相关文章

spring与mybatis整合配置MapperFactoryBean 与 MapperScannerConfigurer区别

MapperFactoryBean 与 MapperScannerConfigurer Spring注入映射器 使用mybatis进行数据处理的四种方式 ①SqlSessionTemplate②SqlSessionDaoSupport③MapperFactoryBean④MapperScannerConfigurer ①SqlSessionTemplate:这个需要写配置文件,在实现类中注入sqlsession,再使用sqlsession,是细颗粒控制(非接口开发) ②SqlSessionDao

Spring+SpringMVC+MyBatis整合配置

前端控制器 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="

idea spring+springmvc+mybatis环境配置整合详解

idea spring+springmvc+mybatis环境配置整合详解 1.配置整合前所需准备的环境: 1.1:jdk1.8 1.2:idea2017.1.5 1.3:Maven 3.5.2 2.查看idea中是否安装Maven插件: 2.1:File --> Settings --> Plugins 2.2:如下图所示的步骤进行操作(注:安装完插件,idea会重新启动) 3.idea创建Maven项目的步骤 4.搭建目录结构 下图就是我搭建Maven项目之后,添加对应的目录和文件 5.p

九 spring和mybatis整合

1       spring和mybatis整合 1.1     整合思路 需要spring通过单例方式管理SqlSessionFactory. spring和mybatis整合生成代理对象,使用SqlSessionFactory创建SqlSession.(spring和mybatis整合自动完成) 持久层的mapper都需要由spring进行管理. 1.2     整合环境 创建一个新的java工程(接近实际开发的工程结构) jar包: mybatis3.2.7的jar包 spring3.2.

Spring与Mybatis整合

1.mybatis-spring.jar简介 Spring与Mybatis整合需要引入一个mybatis-spring.jar文件包,该整合包由Mybatis提供,可以从Mybatis官网下载. mybatis-spring.jar提供了下面几个与整合相关的API SqlSessionFactoryBean 为整合应用提供SqlSession对象资源 MapperFactoryBean 根据指定Mapper接口生成Bean实例 MapperScannerConfigurer 根据指定包批量扫描M

Springmvc+spring+maven+Mybatis整合

随着springmvc及maven越来越受到众多开发者的青睐,笔者主要结合springmvc+maven+spring+Mybatis,搭建一套用于开发和学习的框架.本文将一步步展示整个框架的搭建过程,方便交流和学习. 一.开发环境: windows 8.1 eclipse Luna Service Release 1 (4.4.1) mysql-5.6.19-winx64 maven-3.2.3 jdk 1.7 apache-tomcat-7.0.57 二.主要技术: springmvc +

spring mvc+mybatis整合 (二)

转:http://lifeneveralone.diandian.com/post/2012-11-02/40042292065 本文介绍使用spring mvc结合Mybatis搭建一个应用程序框架. demo源码下载:springMVC-Mybatis 1.准备工作: spring的jar包: spring-beans-3.1.0.RELEASE.jar spring-core-3.1.0.RELEASE.jar spring-web-3.1.0.RELEASE.jar spring-web

Spring+SpringMVC +MyBatis整合配置文件案例66666

Spring+SpringMVC +MyBatis整合配置文件案例 标签: springspringmvcmybatismvcjava 2017-04-13 19:12 228人阅读 评论(1) 收藏 举报 分类: java_javaSE(2) 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] Spring+SpringMVC +MyBatis整合配置文件案例 针对spring/SpringMVC/MyBatis三个框架的整合有很多的方式,经过最近的学习我来总结一下其配置文

Mybatis学习--spring和Mybatis整合

简介 在前面写测试代码的时候,不管是基于原始dao还是Mapper接口开发都有许多的重复代码,将spring和mybatis整合可以减少这个重复代码,通过spring的模板方法模式,将这些重复的代码进行封装,如:获取SqlSessionFactory.SqlSession.SqlSession的关闭等,我们只需要实现具体的业务处理.另外,spring还利用其IOC将Dao或者Mapper接口的放入到容器中进行管理,更好的实现了解耦. Spring和MyBatis整合 1.整合思路: 需要spri