<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
">
<!-- 启用注解 -->
<context:annotation-config />
<!-- 扫描指定包中的所有的对象 -->
<context:component-scan base-package="com.etc.service" />
<!-- 这个Bean用于读取数据库连接相关的属性文件 -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:config/jdbc.properties"/>
</bean>
<!-- 配置数据源及连接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<!-- ${driver}取属性文件中: driver键的值 -->
<property name="driverClassName" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
<property name="initialSize" value="${initialSize}"/>
<property name="maxActive" value="${maxActive}"/>
<property name="maxIdle" value="${maxIdle}"/>
<property name="minIdle" value="${minIdle}"/>
</bean>
<!-- 根据数据源dataSource,配置MyBatis访问数据库,加载映射文件。 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 数据源对象 -->
<property name="dataSource" ref="dataSource"/>
<!-- 加载所有的映射文件 *表示通配符-->
<property name="mapperLocations" value="classpath:com/etc/mapping/*.xml"/>
<!-- 如果有MyBatis的主配置文件,则加载主配置文件,否则就要加载实体类的别名 -->
<property name="configLocation" value="classpath:config/mybatis-config.xml"/>
<!--如果没有mybatis的主配置文件 扫描entity层中所有的实体,给实体对象取别名 -->
<!-- <property name="typeAliasesPackage" value="com.etc.entity"/> -->
</bean>
<!-- 启用事务注解 transaction-manager="transactionManager"引用事务管理Bean -->
<tx:annotation-driven transaction-manager="transactionManager" />
<!-- 配置事务管理Bean -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- 事务处理需要依赖数据源对象 -->
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>