<?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"
>-->
<!-- xmlns 是xml的命名空间
要引入新的 context命名空间
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<!--
读取 jdbc.properties 中的内容
property-placeholder: 占位符
location: 属性文件的位置
-->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!-- 1) 获得数据库连接池对象,并交由 spring 同一管理 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" >
<!-- 可以利用 ${key} 获取 jdbc.properties 文件中的值,连接数据库的驱动,连接字符串,用户名和登录密码-->
<property name="driverClassName" value="${driverClassName}"></property>
<property name="url" value="${url}"></property>
<property name="username" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean>
<!-- 2) 获取 SqlSessionFactory 对象,并交由 spring 管理-->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 注入连接池
给 sqlsessionFactory 的属性 dataSource 赋值
ref="引用该 spring容器 中的另一个 bean的id"
-->
<property name="dataSource" ref="dataSource"/>
<!-- 注入 映射文件 mapper
给 sqlsessionFactory 的属性 configLocation 赋值
value="映射文件 XXXmapper.xml 的相对路径"
-->
<property name="configLocation" value="classpath:myBatis.xml"/>
</bean>
<!--配置IStudentMapper对象,把IStudentMapper配置文件自动配置成 spring 中的 <bean>-->
<bean id="IStudentMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<!-- name="mapperInterface":映射器接口, 从这个包开始扫描-->
<property name="mapperInterface" value="org.mhz.dao.IStudentDao"/>
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
<!--配置IClassMapper对象,把IClassMapper配置文件自动配置成 spring 中的 <bean>-->
<bean id="IClassMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<!-- name="mapperInterface":映射器接口, 从这个包开始扫描-->
<property name="mapperInterface" value="org.mhz.dao.IClassInfoDao"/>
<property name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
</beans>