配置c3po数据源
<!-- 配置DataSource数据源,使用c3p0连接池 -->
<bean id="dataSource"
class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="${db.driver}" />
<property name="jdbcUrl" value="${db.url}" />
<property name="user" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="acquireIncrement" value="3" />
<property name="acquireRetryAttempts" value="5" />
<property name="acquireRetryDelay" value="500" />
<property name="checkoutTimeout" value="60000" />
<property name="initialPoolSize" value="10" />
<property name="maxPoolSize" value="30" />
<property name="maxStatementsPerConnection" value="10" />
<property name="maxStatements" value="100" />
<property name="numHelperThreads" value="10" />
<property name="autoCommitOnClose" value="true"/>
<property name="breakAfterAcquireFailure" value="false"/>
</bean>
配置myBatis
<!-- XML方式的配置 -->
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation"
value="/WEB-INF/conf/mybatis-config.xml" />
<property name="mapperLocations"
value="/WEB-INF/conf/mapper/*Mapper.xml" />
</bean>
配置mapper接口的自动扫描
<!-- 基包扫描,自动生成相对应的MapperFactoryBean类-->
<!-- 属性sqlSessionFactory可以不配置,如果是多数据源的话,则需要针对数据源进行配置 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.huawei.dao.mapper" />
</bean>