spring-mybatis.xml
5.56 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<!-- yoho_passport 数据源 -->
<bean id="yohobuylogsMasterDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.mysql.driver}" />
<property name="url" value="${jdbc.mysql.yohopassport.master.url}" />
<property name="username" value="${jdbc.mysql.yohopassport.username}" />
<property name="password" value="${jdbc.mysql.yohopassport.password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${jdbc.mysql.initialSize}"></property>
<!-- 连接池最大数量 -->
<property name="maxActive" value="${jdbc.mysql.maxActive}"></property>
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${jdbc.mysql.maxIdle}"></property>
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${jdbc.mysql.minIdle}"></property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${jdbc.mysql.maxWait}"></property>
<!--定时对线程池中的链接进行校验 -->
<property name="testWhileIdle" value="${jdbc.mysql.testWhileIdle}"></property>
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.mysql.timeBetweenEvictionRunsMillis}"></property>
<property name="validationQuery" value="${jdbc.mysql.validationQuery}"></property>
<property name="testOnBorrow" value="${jdbc.mysql.testOnBorrow}"></property>
<property name="testOnReturn" value="${jdbc.mysql.testOnReturn}"></property>
</bean>
<bean id="yohobuylogsSlaveDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.mysql.driver}" />
<property name="url" value="${jdbc.mysql.yohopassport.slave.url}" />
<property name="username" value="${jdbc.mysql.yohopassport.username}" />
<property name="password" value="${jdbc.mysql.yohopassport.password}" />
<!-- 初始化连接大小 -->
<property name="initialSize" value="${jdbc.mysql.initialSize}"></property>
<!-- 连接池最大数量 -->
<property name="maxActive" value="${jdbc.mysql.maxActive}"></property>
<!-- 连接池最大空闲 -->
<property name="maxIdle" value="${jdbc.mysql.maxIdle}"></property>
<!-- 连接池最小空闲 -->
<property name="minIdle" value="${jdbc.mysql.minIdle}"></property>
<!-- 获取连接最大等待时间 -->
<property name="maxWait" value="${jdbc.mysql.maxWait}"></property>
<!--定时对线程池中的链接进行校验 -->
<property name="testWhileIdle" value="${jdbc.mysql.testWhileIdle}"></property>
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.mysql.timeBetweenEvictionRunsMillis}"></property>
<property name="validationQuery" value="${jdbc.mysql.validationQuery}"></property>
<property name="testOnBorrow" value="${jdbc.mysql.testOnBorrow}"></property>
<property name="testOnReturn" value="${jdbc.mysql.testOnReturn}"></property>
</bean>
<bean id="dynamicDataSource" class="com.yoho.core.dal.datasource.DynamicDataSource">
<property name="defaultTargetDataSource" ref="yohobuylogsMasterDataSource" />
<property name="targetDataSources">
<map>
<entry key="yohobuylogsMasterDataSource" value-ref="yohobuylogsMasterDataSource" />
</map>
</property>
</bean>
<bean id="multipleDataSourceRouter" class="com.yoho.core.dal.datasource.MultiDataSourceRouter">
<property name="defaultDBCluster" value="yohobuylogsDbCluster" />
<property name="readOnlyInSlave" value="${jdbc.mysql.readonlyinslave:false}" />
<property name="dbClusterSet">
<map>
<entry key="yohobuylogsDbCluster" value="yohobuylogsMasterDataSource,yohobuylogsMasterDataSource" />
</map>
</property>
<property name="daoDbClusterMap">
<map>
</map>
</property>
</bean>
<bean id="dataSourceMethodInterceptor" class="com.yoho.core.dal.datasource.DataSourceMethodInterceptor">
</bean>
<aop:config>
<aop:pointcut id="daoPoint" expression="execution(* com.yoho.*.dal.*.*(..)) " />
<aop:advisor pointcut-ref="daoPoint" advice-ref="dataSourceMethodInterceptor" />
</aop:config>
<!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dynamicDataSource" />
<!-- 自动扫描mapping.xml文件 -->
<property name="mapperLocations" value="classpath*:META-INF/mybatis/*.xml"></property>
</bean>
<!-- DAO接口所在包名,Spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.yoho.*.dal" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
</beans>