mybatis.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--mybatis主配置文件-->
<!-- 引入配置文件-->
<bean id="placeholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="jdbc.properties"></property>
</bean>
<!-- 配置数据源-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${driver}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${username}"></property>
<property name="password" value="${password}"></property>
<!-- 初始化连接大小-->
<property name="initialSize" value="${initialSize}"></property>
<!-- 连接池最大数量-->
<property name="maxActive" value="${maxActive}"></property>
<!-- 连接池最大空闲-->
<property name="maxIdle" value="${maxIdle}"></property>
<!-- 连接池最小空闲-->
<property name="minIdle" value="${minIdle}"></property>
<!-- 获取链接最大等待时间-->
<property name="maxWait" value="${maxWait}"></property>
</bean>
<!-- spring和Mybatis完美整合,不需要mybatis的映射文件-->
<bean class="org.mybatis.spring.SqlSessionFactoryBean" id="sqlSessionFactory">
<property name="dataSource" ref="dataSource"></property>
<!-- 自动扫描mapperxml文件夹 类似于mybatis中主配置文件Mapper.xml文件 中的mappers-->
<property name="mapperLocations" value="classpath:mapperxml/*xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的接口类-->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.dao"></property>
</bean>
</beans>
spring.xml
<?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">
<!--spring的核心配置文件-->
<context:component-scan base-package="com.service"></context:component-scan>
<!--<bean class="com.service.impl.StudentServiceImpl" id="studentService">
<property name="studentMapper" ref="studentMapper"></property>
</bean>-->
<!-- 包含mybatis的核心配置文件-->
<import resource="springMybatis.xml"></import>
</beans>
jdbc.properties
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/demo
username=root
password=root
initialSize=0
maxActive=20
maxIdle=20
minIdle=1
maxWait=60000