spring-config-dao.xml
5.06 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
106
107
108
109
110
<?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:aop="http://www.springframework.org/schema/aop"
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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"
default-autowire="byName">
<context:component-scan base-package="com.dili.titan.dao" />
<bean id="baseDataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="filters" value="stat"/>
<property name="maxActive" value="${jdbc.maxActive}"/>
<property name="initialSize" value="${jdbc.initialSize}"/>
<property name="maxWait" value="${jdbc.maxWait}"/>
<property name="minIdle" value="${jdbc.minIdle}"/>
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}"/>
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}"/>
<property name="validationQuery" value="SELECT now()"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnBorrow" value="false"/>
<property name="testOnReturn" value="false"/>
<property name="poolPreparedStatements" value="${jdbc.poolPreparedStatements}"/>
<property name="maxOpenPreparedStatements" value="${jdbc.maxOpenPreparedStatements}"/>
</bean>
<bean id="masterDataSource" parent="baseDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClass}"/>
<property name="url" value="${master.jdbcUrl}"/>
<property name="username" value="${master.jdbc.username}"/>
<property name="password" value="${master.jdbc.password}"/>
</bean>
<bean id="slaveDataSource" parent="baseDataSource"
init-method="init" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClass}"/>
<property name="url" value="${slave.jdbcUrl}"/>
<property name="username" value="${slave.jdbc.username}"/>
<property name="password" value="${slave.jdbc.password}"/>
</bean>
<bean id="dynamicDataSource" class="com.dili.titan.common.datasource.DynamicDataSource">
<property name="masterDataSources">
<map key-type="java.lang.String">
<!-- write key从1,2,3...按顺序开始命名-->
<entry key="master1" value-ref="masterDataSource"/>
</map>
</property>
<property name="slaveDataSources">
<map key-type="java.lang.String">
<!-- read key从1,2,3...按顺序开始命名-->
<entry key="slave1" value-ref="slaveDataSource"/>
</map>
</property>
<property name="defaultTargetDataSource" ref="masterDataSource"/>
</bean>
<bean id="manyDataSourceAspect" class="com.dili.titan.common.datasource.DataSourceAspect">
<property name="mastersCount" value="1"/>
</bean>
<aop:config>
<aop:aspect id="c" ref="manyDataSourceAspect">
<aop:pointcut id="tx" expression="@within(com.dili.titan.common.datasource.DynamicSource)"/>
<!--<aop:before pointcut-ref="tx" method="before"/>-->
<!--<aop:before pointcut-ref="tx" method="after"/>-->
<aop:around pointcut-ref="tx" method="around"/>
</aop:aspect>
</aop:config>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dynamicDataSource" />
</bean>
<!-- 集成Mybatis -->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dynamicDataSource" />
<property name="configLocation" value="classpath:sqlmap-config.xml" />
</bean>
<bean id="sqlTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sessionFactory" />
</bean>
<bean id="batchSqlTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="sessionFactory" />
<constructor-arg index="1" value="BATCH" />
</bean>
<bean id="productDescDao" class="com.dili.titan.dao.impl.ProductDescDaoImpl">
<property name="tableName" value="agriez_titan"/>
<property name="family" value="f1" />
<property name="qualifier" value="product_desc" />
<property name="suffix" value="_product_desc" />
</bean>
<bean id="templeteDescDao" class="com.dili.titan.dao.impl.TempleteDescDaoImpl">
<property name="tableName" value="agriez_titan_templeteDesc"/>
<property name="family" value="f2" />
<property name="qualifier" value="templete_desc" />
<property name="suffix" value="_templete_desc" />
</bean>
</beans>