|
|
|
|
<?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"
|
|
|
|
|
xmlns:tx="http://www.springframework.org/schema/tx"
|
|
|
|
|
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-4.3.xsd
|
|
|
|
|
http://www.springframework.org/schema/tx
|
|
|
|
|
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
|
|
|
|
|
<!-- 整合MyBatis 开始 -->
|
|
|
|
|
<!--创建jdbc数据源 -->
|
|
|
|
|
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
|
|
|
|
|
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
|
|
|
|
|
<property name="username" value="root" />
|
|
|
|
|
<property name="password" value="zjh19990323" />
|
|
|
|
|
<property name="url"
|
|
|
|
|
value="jdbc:mysql://127.0.0.1:3306/zxzx?useUnicode=true&characterEncoding=utf8" />
|
|
|
|
|
</bean>
|
|
|
|
|
<!-- 配置MyBatis的sqlSession -->
|
|
|
|
|
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
|
|
|
|
|
<property name="configLocation" value="classpath:mybatis.xml" />
|
|
|
|
|
<property name="mapperLocations" value="classpath:mapper/*.xml" />
|
|
|
|
|
<property name="dataSource" ref="dataSource" />
|
|
|
|
|
</bean>
|
|
|
|
|
<!-- 映射Mapper目录 -->
|
|
|
|
|
<!-- Mapper接口所在包名,Spring会自动查找其下的Mapper -->
|
|
|
|
|
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
|
|
|
|
|
<property name="basePackage" value="mapperDAO" />
|
|
|
|
|
</bean>
|
|
|
|
|
<!-- 可通过注解控制事务 -->
|
|
|
|
|
<tx:annotation-driven transaction-manager="transactionManager" />
|
|
|
|
|
<bean id="transactionManager"
|
|
|
|
|
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
|
|
|
|
<property name="dataSource" ref="dataSource" />
|
|
|
|
|
</bean>
|
|
|
|
|
<!-- 整合MyBatis 结束 -->
|
|
|
|
|
</beans>
|