spring XML 선언부

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
   
   
    <!--
     datasource 설정(propertyConfigurer 활용)
     com.synervelly.common.web.dataaccess 여기서 다른 객체를 받는다.
    -->
    <alias name="dataSource-${First.DbType}"  alias="dataSource1" />
    <alias name="dataSource-${Second.DbType}" alias="dataSource2" /><!-- 다른 데이터 소스를 받을수 있음. -->
       
   
    <!-- Oracle -->
    <bean id="dataSource-oracle" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${First.DriverClassName}"/>
        <property name="url" value="${First.Url}" />
        <property name="username" value="${First.UserName}"/>
        <property name="password" value="${First.Password}"/>
        <property name="initialSize" value="10"/>
        <property name="maxActive" value="10"/>
        <property name="maxIdle" value="5"/>
        <property name="maxWait" value="10000"/>       
    </bean>
   
     <!-- MS-SQL2008 -->
    <bean id="dataSource-mssql" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${Second.DriverClassName}"/>
        <property name="url" value="${Second.Url}" />
        <property name="username" value="${Second.UserName}"/>
        <property name="password" value="${Second.Password}"/>
        <property name="initialSize" value="10"/>
        <property name="maxActive" value="10"/>
        <property name="maxIdle" value="5"/>
        <property name="maxWait" value="10000"/>       
    </bean>   
</beans> 

위 파란색 부분은 프로퍼티 값에서 가져와 입력되는 점을 참고 하시면 됩니다.

ibatis  XML

<?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:util="http://www.springframework.org/schema/util"
    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/util http://www.springframework.org/schema/util/spring-util-3.1.xsd          
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

    <!-- lob Handler -->
    <bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true" />

    <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient1" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocations">
            <list>
                <value>classpath:config/sqlmap/${First.DbType}/*.xml</value>
            </list>
        </property>
        <property name="dataSource" ref="dataSource-${First.DbType}"/>
        <property name="lobHandler" ref="lobHandler"/>
    </bean>
   
   
     <!-- SqlMap setup for iBATIS Database Layer -->
    <bean id="sqlMapClient2" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocations">
            <list>
                <value>classpath:config/sqlmap/${Second.DbType}/*.xml</value>
            </list>
        </property>
        <property name="dataSource" ref="dataSource-${Second.DbType}"/>
        <property name="lobHandler" ref="lobHandler"/>
    </bean>
   
   
   
  
     
</beans>   
 

 

위와같이 선언 하면 각 각 2개의 데이터 소스를 사용할 수 있다.

DAO 부분

 

public class WebAbstractSecondDAO  extends SqlMapClientDaoSupport {
  
    protected WebAbstractSecondDAO() {
           }

    /**
     * Annotation 형식으로 sqlMapClient 를 받아와 이를
     * super(SqlMapClientDaoSupport) 의 setSqlMapClient
     * 메서드를 호출하여 설정해 준다.
     * @param sqlMapClient  
     */
    @Resource(name = "sqlMapClient1")
    public void setSuperSqlMapClient(SqlMapClient sqlMapClient) {
        super.setSqlMapClient(sqlMapClient);
    }

     } 

 

이노테이션을 이용하여

리소스를 주입힌다 .

 @Resource(name = "sqlMapClient1") 이부분