Fork me on GitHub

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>

 

posted @ 2015-06-09 23:30  森林森  阅读(531)  评论(0编辑  收藏  举报