本文件的作用:
1整合dao层,连接数据库
2设置数据库连接池
3配置SqlSessionFactory对象
4配置扫描Dao接口包,动态实现dao接口,注入到spring容器中
Ps:此文件可以替代mybatis-config.xml文件(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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!-- 整合数据库-->
<context:property-placeholder location="classpath:databases.properties"/>
<!-- 设置数据库连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!--配置连接处属性-->
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="jdbc.url"/>
<property name="user" value="jdbc.username"/>
<property name="password" value="${jdbc.password}"/>
<!--c3p0连接池的私有属性-->
<property name="maxPoolSize" value="30"/>
<property name="minPoolSize" value="10"/>
<!--关闭连接不自动commit-->
<property name="autoCommitOnClose" value="false"/>
<!--获取连接超时时间-->
<property name="checkoutTimeout" value="3000"/>
<!--当获取链接失败重试次数-->
<property name="acquireRetryAttempts" value="2"/>
</bean>
<!--3.配置SqlSessionFactory对象-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--注入数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!--配置mybatis全局配置文件-->
<property name="configLocation" value="classpath:applicartionContext.xml"/>
</bean>
<!--4.配置扫描Dao接口包,动态实现dao接口,注入到spring容器中-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!--注入sqlSessionFactory-->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
<!--给出需要扫描dao接口包-->
<property name="basePackage" value="r"/>
</bean>
</beans>