Spring + Struts + ibatis 에서 데이터 읽 기와 쓰기 분리 및 사무 설정 (2)
5. spring - datasource. xml 설정 (필요 에 따라 이름 을 정의 하거나 spring 메 인 프로필 에 쓸 수 있 습 니 다)
<?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:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- JDBC -->
<bean id="propertyConfig"
class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<!-- -->
<bean id="parentDataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="initialSize" value="10" />
<property name="maxActive" value="100" />
<property name="maxIdle" value="30" />
<property name="minIdle" value="10" />
<property name="logAbandoned" value="true" />
<property name="removeAbandoned" value="true" />
<property name="removeAbandonedTimeout" value="100" />
<property name="maxWait" value="5000" />
<property name="testOnBorrow" value="true"/>
<property name="testOnReturn" value="true"/>
<property name="testWhileIdle" value="true"/>
<property name="minEvictableIdleTimeMillis" value="0"></property>
<property name="timeBetweenEvictionRunsMillis" value="60"></property>
</bean>
<!-- ( UPDATE ) -->
<bean id="masterDataSource" parent="parentDataSource">
<property name="driverClassName" value="${master.jdbc.driverClassName}" />
<property name="url" value="${master.jdbc.url}" />
<property name="username" value="${master.jdbc.username}" />
<property name="password" value="${master.jdbc.password}" />
<property name="validationQuery" value="SELECT COUNT(1) FROM tbl_test"></property>
</bean>
<!-- ( UPDATE ) -->
<bean id="slaveDataSource" parent="parentDataSource">
<property name="driverClassName" value="${slave.jdbc.driverClassName}" />
<property name="url" value="${slave.jdbc.url}" />
<property name="username" value="${slave.jdbc.username}" />
<property name="password" value="${slave.jdbc.password}" />
<property name="validationQuery" value="SELECT COUNT(1) FROM tbl_test"></property>
</bean>
<!-- -->
<bean id="dataSource" class="com.ssi222.wilr.util.datasource.DynamicDataSource">
<property name="targetDataSources">
<map key-type="java.lang.String">
<entry key="master" value-ref="masterDataSource" />
<entry key="slave" value-ref="slaveDataSource" />
</map>
</property>
<property name="defaultTargetDataSource" ref="masterDataSource"></property>
</bean>
<!--Spring|Ibatis -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocations">
<list>
<value>classpath:config/ibatis.xml</value>
</list>
</property>
<property name="dataSource">
<ref local="dataSource" />
</property>
</bean>
<!-- -->
<bean id="presentation" class="com.ssi222.wilr.presentation.impl.PresentationImpl">
<property name="sqlMapClient">
<ref local="sqlMapClient" />
</property>
</bean>
<!-- -->
<bean id="baseService" class="com.ssi222.wilr.service.impl.BaseServiceImpl">
<property name="presentation">
<ref local="presentation" />
</property>
</bean>
</beans>