spring-mybatis.xml
2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/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/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"
default-lazy-init="true">
<!-- MyBatis配置 -->
<bean id="sqlSessionFactoryMySql" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceMySql" />
<property name="configLocation" value="classpath:/mybatis/mybatis-config.xml" />
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<property name="typeAliasesPackage" value="com.cjs.cms.model" />
<!-- 显式指定Mapper文件位置 -->
<property name="mapperLocations" value="classpath:/mybatis/**/*-mapper.xml" />
</bean>
<bean id="sqlSessionFactoryOracle" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSourceOracle" />
<property name="configLocation" value="classpath:/mybatis/mybatis-config.xml" />
<!-- 自动扫描entity目录, 省掉Configuration.xml里的手工配置 -->
<property name="typeAliasesPackage" value="com.cjs.cms.model" />
<!-- 显式指定Mapper文件位置 -->
<property name="mapperLocations" value="classpath:/mybatis/**/*-mapper.xml" />
</bean>
<!-- 扫描basePackage下所有以@Repository标识的 接口 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.cjs.cms.dao" />
<property name="annotationClass" value="org.springframework.stereotype.Repository" />
<property name="sqlSessionTemplateBeanName" value="routingSqlSessionTemplate" />
</bean>
<bean id="routingSqlSessionTemplate" class="com.cjs.cms.util.db.RoutingSqlSessionTemplate">
<constructor-arg ref="sqlSessionFactoryMySql" />
<property name="targetSqlSessionFactorys">
<map>
<entry key="mysql" value-ref="sqlSessionFactoryMySql" />
<entry key="oracle" value-ref="sqlSessionFactoryOracle" />
</map>
</property>
</bean>
</beans>