<?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-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
">
<!-- 1.数据库连接配置 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 2.配置连接池 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<!-- 配置连接池属性 -->
<property name="driverClass" value="${mysql.driverClassName}" />
<property name="jdbcUrl" value="${mysql.jdbc.url}" />
<property name="user" value="${mysql.jdbc.username}" />
<property name="password" value="${mysql.jdbc.password}" />
<!-- c3p0连接池的私有属性 -->
<property name="initialPoolSize" value="10" />
<property name="minPoolSize" value="10" />
<property name="maxPoolSize" value="200" />
<property name="maxIdleTime" value="7200" />
<property name="acquireIncrement" value="10" />
<property name="checkoutTimeout" value="10000" />
<property name="maxIdleTimeExcessConnections" value="10" />
<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:mybatis-config.xml"></property>
<!-- 扫描实体包 使用别名-->
<property name="typeAliasesPackage" value="com.yyc.demo.enity" />
<!-- 扫描sql配置文件:mapper需要的xml文件 -->
<property name="mapperLocations" value="classpath:com/yyc/demo/mapping/*.xml" />
</bean>
<!-- 4.自动扫描DAO接口包,动态实现DAO接口,并注入到spring容器中 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 注入sqlSessionFactory -->
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
<!-- 自动扫描的DAO包 -->
<property name="basePackage" value="com.yyc.demo.dao" />
</bean>
</beans>
原文地址:http://881206524.blog.51cto.com/10315134/1832967