首页 > 编程语言 > 详细

spring和mybatis整合配置

时间:2015-06-10 01:05:03      阅读:226      评论:0      收藏:0      [点我收藏+]
<?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>

 

spring和mybatis整合配置

原文:http://www.cnblogs.com/liunanjava/p/4564895.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!