spring多数据源配置

spring配置文件:

<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"

xmlns:tx="http://www.springframework.org/schema/tx"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd       

     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-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"

default-lazy-init="true">

    

<bean id= "propertyConfigurer"          

      class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >          

  <property name="location"  value= "jdbc.properties" />          

</bean>     

<!-- 配置数据源ETL  -->       

<bean id="dataSourceETL" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">      

  <property name="driverClassName"  value= "${jdbc.driverClassName}"  />          

  <property name="url"  value= "${jdbc.url}" />          

  <property name="username"  value= "${jdbc.username}"  />          

  <property name="password"  value= "${jdbc.password}"  />    

  <property name="initialSize" value="${jdbc.initialSize}"/>

      <property name="maxActive" value="${jdbc.maxActive}"/>      

</bean>

<!-- 配置数据源注册系统  -->       

<bean id="dataSourceRegister" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">      

  <property name="driverClassName"  value= "${db.driver}"  />          

  <property name="url"  value= "${db.url}" />          

  <property name="username"  value= "${db.username}"  />          

  <property name="password"  value= "${db.password}"  />    

  <property name="initialSize" value="${db.initialSize}"/>

      <property name="maxActive" value="${db.maxActive}"/>      

</bean>

<!-- 事务 ETL --> 

<bean id="transactionManagerETL"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSourceETL" />

</bean>

<!-- 事务Register --> 

<bean id="transactionManagerRegister"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSourceRegister" />

</bean>

<!-- 事务拦截ETL -->    

    <bean id="transactionInterceptorETL" class="org.springframework.transaction.interceptor.TransactionInterceptor">    

        <property name="transactionManager" ref="transactionManagerETL" />    

        <property name="transactionAttributes">    

        <props>    

            <prop key="insert*">PROPAGATION_REQUIRED</prop>    

            <prop key="delete*">PROPAGATION_REQUIRED</prop>    

            <prop key="update*">PROPAGATION_REQUIRED</prop>    

            <prop key="do*">PROPAGATION_REQUIRED</prop>    

        </props>    

        </property>    

    </bean>  

      

    <!-- 事务拦截Register -->    

    <bean id="transactionInterceptorRegister" class="org.springframework.transaction.interceptor.TransactionInterceptor">    

        <property name="transactionManager" ref="transactionManagerRegister" />    

        <property name="transactionAttributes">    

        <props>    

            <prop key="insert*">PROPAGATION_REQUIRED</prop>    

            <prop key="delete*">PROPAGATION_REQUIRED</prop>    

            <prop key="update*">PROPAGATION_REQUIRED</prop>    

            <prop key="do*">PROPAGATION_REQUIRED</prop>    

        </props>    

        </property>    

    </bean>    

        

    <!--  管理你连接的地方-->    

    <bean id="autoProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">    

        <property name="beanNames">    

        <value>*Service</value>    

        </property>    

        <property name="interceptorNames">    

            <list>    

            <value>transactionInterceptorETL</value>    

            <value>transactionInterceptorRegister</value>    

            </list>    

        </property>    

    </bean> 

    

<!-- ibatis的工厂数据源配置ETL -->    

    <bean id="sqlMapClientETL" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">    

        <property name="configLocation" value="sql-map-config.xml" />

        <property name="dataSource" ref="dataSourceETL" />    

    </bean>    

        

    <!-- ibatis的工厂数据源配置Register -->    

    <bean id="sqlMapClientRegister" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">    

        <property name="configLocation" value="sql-map-config.xml" />   

        <property name="dataSource" ref="dataSourceRegister" />    

    </bean>   

    

   

<!--开始 : ETL数据源的业务 -->   

<bean id="jobAction" class="com.tydic.etl.action.job.JobAction">

<property name="jobService" ref="jobService"/>

<property name="directoryService" ref="directoryService"/>

<property name="databaseService" ref="databaseService"/>

<property name="monitorViewService" ref="monitorViewService"/>

    </bean>

    

    <bean id="monitorViewService" class="com.tydic.etl.service.monitor.MonitorViewServiceImpl">

     <property name="monitorViewDao" ref="monitorViewDao"/>

    </bean>

    <bean id="monitorViewDao" class="com.tydic.etl.dao.monitor.MonitorViewDao">

<property name="sqlMapClient" ref="sqlMapClientETL"/>

    </bean>

    

    <bean id="jobService" class="com.tydic.etl.service.job.JobServiceImpl">

     <property name="jobdao" ref="jobdao"/>

    

     <!--开始: 注册系统查询数据源的业务 --> 

     <property name="registerdao" ref="registerdao"/>

     <!--结束:注册系统查询数据源的业务 -->

    

    </bean>

    <bean id="jobdao" class="com.tydic.etl.dao.job.JobDao">

<property name="sqlMapClient" ref="sqlMapClientETL"/>

    </bean>

    

    <bean id="directoryService" class="com.tydic.etl.service.directory.DirectoryServiceImpl">

     <property name="directoryDao" ref="directoryDao"/>

    </bean>

    <bean id="directoryDao" class="com.tydic.etl.dao.RDirectoryDao">

<property name="sqlMapClient" ref="sqlMapClientETL"/>

    </bean>

    

    <bean id="databaseService" class="com.tydic.etl.service.database.RDatabaseServiceImpl">

     <property name="databaseDao" ref="databaseDao"/>

    </bean>

    <bean id="databaseDao" class="com.tydic.etl.dao.database.RDatabaseDao">

<property name="sqlMapClient" ref="sqlMapClientETL"/>

    </bean>

    <!--结束: ETL数据源的业务 --> 

    

    <!--开始: 注册系统查询数据源的业务 --> 

    <bean id="registerdao" class="com.tydic.etl.dao.job.RegisterDao">

<property name="sqlMapClient" ref="sqlMapClientRegister"/>

    </bean>

    <!--结束:注册系统查询数据源的业务 -->  

 

</beans>

参考文献:

http://blog.csdn.net/wangpeng047/article/details/8866239

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值