spring-mybatis.xml 2.31 KB
<?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" xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
           	http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
           	http://www.springframework.org/schema/context
           	http://www.springframework.org/schema/context/spring-context-4.0.xsd
           	http://www.springframework.org/schema/tx
      		http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
           	http://www.springframework.org/schema/aop
           	http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
			http://www.springframework.org/schema/jdbc
			http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd" default-lazy-init="true">

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
		<property name="typeAliasesPackage" value="cn.runsa.portal.entity" />
		<property name="mapperLocations" value="classpath*:mybatis/mysql/*Mapper.xml" /><!-- *不行就替换成?    *Mapper 匹配当前文件夹  **/*Mapper匹配所有文件夹-->
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 扫描basePackage下所有以@MyBatisRepository标识的 接口 ,相当于实现dao.impl层 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="cn.runsa.portal.query.dao" />
	</bean>

	<!-- ***************事务处理************************* -->
	<bean name="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 自动事务 方法加添加 @Transactional -->
	<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />

	<context:property-override location="classpath:datasource.properties" />
	<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"></bean>
</beans>