`
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--包掃描-->
<context:component-scan base-package="com.mmall" annotation-config="true"/>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="order" value="2"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="locations">
<list>
<value>classpath:datasource.properties</value>
</list>
</property>
<property name="fileEncoding" value="utf-8"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driverClassName}"/>
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
<!-- 連接池啟動(dòng)時(shí)的初始值 -->
<property name="initialSize" value="${db.initialSize}"/>
<!-- 連接池的最大值 -->
<property name="maxActive" value="${db.maxActive}"/>
<!-- 最大空閑值.當(dāng)經(jīng)過一個(gè)高峰時(shí)間后郊愧,連接池可以慢慢將已經(jīng)用不到的連接慢慢釋放一部分,一直減少到maxIdle為止 -->
<property name="maxIdle" value="${db.maxIdle}"/>
<!-- 最小空閑值.當(dāng)空閑的連接數(shù)少于閥值時(shí)眠寿,連接池就會(huì)預(yù)申請去一些連接焦蘑,以免洪峰來時(shí)來不及申請 -->
<property name="minIdle" value="${db.minIdle}"/>
<!-- 最大建立連接等待時(shí)間。如果超過此時(shí)間將接到異常狡逢。設(shè)為-1表示無限制 -->
<property name="maxWait" value="${db.maxWait}"/>
<!--#給出一條簡單的sql語句進(jìn)行驗(yàn)證 -->
<!--<property name="validationQuery" value="select getdate()" />-->
<property name="defaultAutoCommit" value="${db.defaultAutoCommit}"/>
<!-- 回收被遺棄的(一般是忘了釋放的)數(shù)據(jù)庫連接到連接池中 -->
<!--<property name="removeAbandoned" value="true" />-->
<!-- 數(shù)據(jù)庫連接過多長時(shí)間不用將被視為被遺棄而收回連接池中 -->
<!--<property name="removeAbandonedTimeout" value="120" />-->
<!-- #連接的超時(shí)時(shí)間甚侣,默認(rèn)為半小時(shí)间学。 -->
<property name="minEvictableIdleTimeMillis" value="${db.minEvictableIdleTimeMillis}"/>
<!--# 失效檢查線程運(yùn)行時(shí)間間隔,要小于MySQL默認(rèn)-->
<property name="timeBetweenEvictionRunsMillis" value="40000"/>
<!--# 檢查連接是否有效-->
<property name="testWhileIdle" value="true"/>
<!--# 檢查連接有效性的SQL語句-->
<property name="validationQuery" value="SELECT 1 FROM dual"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath*:mappers/*Mapper.xml"></property>
<!-- 分頁插件 -->
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<value>
dialect=mysql
</value>
</property>
</bean>
</array>
</property>
</bean>
<bean name="mapperScannerConfigurer" class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mmall.dao"/>
</bean>
<!-- 使用@Transactional進(jìn)行聲明式事務(wù)管理需要聲明下面這行 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<!-- 事務(wù)管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
<property name="rollbackOnCommitFailure" value="true"/>
</bean>
</beans>