-
Notifications
You must be signed in to change notification settings - Fork 224
/
spring.xml
94 lines (82 loc) · 4.94 KB
/
spring.xml
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
<?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:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
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-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="com.aixuexiao"/>
<!-- 加载配置文件 -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
</bean>
<!-- 配置数据源 -->
<bean id="readDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl">
<value><![CDATA[jdbc:mysql://${db.read.host}:${db.read.port}/${db.read.database}?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull&rewriteBatchedStatements=true]]></value>
</property>
<property name="user" value="${db.read.userName}" />
<property name="password" value="${db.read.password}" />
<property name="maxPoolSize" value="12" />
<property name="minPoolSize" value="0" />
<property name="maxStatements" value="100" />
<property name="initialPoolSize" value="3" />
<property name="maxIdleTime" value="10"/>
<property name="idleConnectionTestPeriod" value="10" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="false" />
<property name="preferredTestQuery" value="SELECT 1 FROM DUAL" />
</bean>
<!-- 配置读的 ibatis (从库)-->
<bean id="readSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="readDataSource" />
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
</bean>
<bean id="readSqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="readSqlSessionFactory" />
</bean>
<!-- 配置数据源(主库) -->
<bean id="writeDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<property name="jdbcUrl">
<value><![CDATA[jdbc:mysql://${db.write.host}:${db.write.port}/${db.write.database}?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull&rewriteBatchedStatements=true]]></value>
</property>
<property name="user" value="${db.write.userName}" />
<property name="password" value="${db.write.password}" />
<property name="maxPoolSize" value="12" />
<property name="minPoolSize" value="0" />
<property name="maxStatements" value="100" />
<property name="initialPoolSize" value="3" />
<property name="maxIdleTime" value="10"/>
<property name="idleConnectionTestPeriod" value="10" />
<property name="testConnectionOnCheckin" value="true" />
<property name="testConnectionOnCheckout" value="false" />
<property name="preferredTestQuery" value="SELECT 1 FROM DUAL" />
</bean>
<!-- 配置写的ibatis (主库)-->
<bean id="writerSqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="writeDataSource" />
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
</bean>
<bean id="writerSqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg index="0" ref="writerSqlSessionFactory" />
</bean>
<!-- 事务控制 (主库)-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="writeDataSource" />
</bean>
</beans>