<?xml version="1.0" encoding="UTF-8"?>
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
<!--要使用注解的話,必須打開該配置項。通過這個配置項,就可以打開針對注解的處理器把它注入到Spring容器中-->
<!-- 資料庫連接配接池 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<!-- 基本參數 -->
<property name="driverClassName" value="${jdbc.mysql.driver}"/>
<property name="url" value="${jdbc.mysql.url}"/>
<property name="username" value="${jdbc.mysql.username}"/>
<property name="password" value="${jdbc.mysql.password}"/>
<property name="connectionProperties" value="${jdbc.mysql.connectionProperties}"/>
<!-- 連接配接資料相關參數 -->
<property name="initialSize" value="${dbcp.initialSize}"/>
<property name="maxActive" value="${dbcp.maxActive}"/>
<property name="maxIdle" value="${dbcp.maxIdle}"/>
<property name="minIdle" value="${dbcp.minIdle}"/>
<property name="maxWait" value="${dbcp.maxWait}"/>
<!-- 事務相關的屬性 -->
<property name="defaultAutoCommit" value="${dbcp.defaultAutoCommit}"/>
<!-- 連接配接健康情況 -->
<property name="timeBetweenEvictionRunsMillis" value="${dbcp.timeBetweenEvictionRunsMillis}"/>
<property name="numTestsPerEvictionRun" value="${dbcp.numTestsPerEvictionRun}"/>
<property name="minEvictableIdleTimeMillis" value="${dbcp.minEvictableIdleTimeMillis}"/>
<property name="testWhileIdle" value="${dbcp.testWhileIdle}"/>
<property name="testOnBorrow" value="${dbcp.testOnBorrow}"/>
<property name="testOnReturn" value="${dbcp.testOnReturn}"/>
<property name="validationQuery" value="${dbcp.validationQuery}"/>
<!-- 連接配接洩漏回收參數 -->
<property name="removeAbandoned" value="${dbcp.removeAbandoned}"/>
<property name="removeAbandonedTimeout" value="${dbcp.removeAbandonedTimeout}"/>
<property name="logAbandoned" value="${dbcp.logAbandoned}"/>
</bean>
<!-- 使用JDBC事物 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 使用annotation注解方式配置事務 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<!-- mybatis 配置 sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:spring/mybatis-config.xml"></property>
<property name="mapperLocations"
value="classpath:mapper/*Mapper.xml">
</property>
</bean>
<!-- mybatis 配置 SQLSession模闆 -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"
scope="prototype">
<constructor-arg index="0" ref="sqlSessionFactory"/>
</bean>
<!-- mybatis 配置 自動生成Dao接口實作 -->
<bean id="mybatisMapper" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage"
value="**.com.公司.系統.**.dao.**"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>
<!--spring 的JDBC模闆 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource">
</property>
</bean>
<!-- 激活掃描 @Repository @Service标注-->
<context:component-scan base-package="**.com.公司.系統.**">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>