zoukankan      html  css  js  c++  java
  • 多数据源配置

    第一步:jdbc.properties配置

    #WMS
    jdbc.driverClassName.oracle_wms=oracle.jdbc.driver.OracleDriver
    jdbc.url.oracle_wms=jdbc:oracle:thin:@xx.xx.xx.xx:1521:dbname
    jdbc.username.oracle_wms=xxx
    jdbc.password.oracle_wms=xxx
    jdbc.min.pool.size_wms=1
    jdbc.max.pool.size_wms=5
    
    
    #TMS
    jdbc.driverClassName.mysql_tms=com.mysql.jdbc.Driver
    jdbc.url.mysql_tms=jdbc:mysql://xx.xx.xx.xx:3306/dbname?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
    jdbc.username.mysql_tms=xxx
    jdbc.password.mysql_tms=xxx
    jdbc.min.pool.size_tms=3
    jdbc.max.pool.size_tms=10

    第二步:applicationContext-datasource.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:context="http://www.springframework.org/schema/context"
           xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
        <context:annotation-config/>
        <bean id="propertyConfigurer" class="com.yyw.scs.framework.kit.CustomizedPropertyConfigurer">
            <!-- 忽略没有找到的资源文件 -->
            <property name="ignoreResourceNotFound" value="true" />
            <property name="locations">
                <list>
                    <value>file:/etc/dbprivatekey.properties</value>
                    <value>classpath*:config/*.properties</value>
                    <value>classpath*:sso.properties</value>
                    <value>classpath*:email.properties</value>
                </list>
            </property>
        </bean>
    
        <bean id="dataSource_wms" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
            <property name="driverClassName" value="${jdbc.driverClassName.oracle_wms}" />
            <property name="url" value="${jdbc.url.oracle_wms}" />
            <property name="username" value="${jdbc.username.oracle_wms}" />
            <property name="password" value="${jdbc.password.oracle_wms}" />
            <property name="maxActive" value="${jdbc.max.pool.size_wms}" />
            <property name="initialSize" value="${jdbc.min.pool.size_wms}" />
            <property name="minIdle" value="${jdbc.min.pool.size_wms}" />
            <property name="testWhileIdle" value="true" />
            <property name="validationQuery" value="select 1 from dual" />
            <property name="filters" value="config" />
        </bean>
    
        <bean id="dataSource_tms" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
            <property name="driverClassName" value="${jdbc.driverClassName.mysql_tms}" />
            <property name="url" value="${jdbc.url.mysql_tms}" />
            <property name="username" value="${jdbc.username.mysql_tms}" />
            <property name="password" value="${jdbc.password.mysql_tms}" />
            <property name="maxActive" value="${jdbc.max.pool.size_tms}" />
            <property name="initialSize" value="${jdbc.min.pool.size_tms}" />
            <property name="minIdle" value="${jdbc.min.pool.size_tms}" />
            <property name="testWhileIdle" value="true" />
            <property name="validationQuery" value="select 1" />
            <property name="filters" value="config" />
        </bean>
    </beans>

    第三步:applicationContext-dao.xml配置

    classpath:wmsmapper/*Mapper.xml
    wmsmapper中mapper文件会找对应数据源
    <?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:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
    
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.yyw.scs.wms.dao" />
            <property name="sqlSessionFactoryBeanName" value="scsSqlSessionBean_wms"/>
        </bean>
        <bean id="scsSqlSessionBean_wms" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource_wms"/>
            <property name="mapperLocations" value="classpath:wmsmapper/*Mapper.xml"/>
            <property name="configLocation" value="classpath:spring/mybatis-configuration.xml"/>
        </bean>
    
        <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="basePackage" value="com.yyw.scs.tms.dao" />
            <property name="sqlSessionFactoryBeanName" value="scsSqlSessionBean_tms"/>
        </bean>
        <bean id="scsSqlSessionBean_tms" class="org.mybatis.spring.SqlSessionFactoryBean">
            <property name="dataSource" ref="dataSource_tms"/>
            <property name="mapperLocations" value="classpath:tmsmapper/*Mapper.xml"/>
            <property name="configLocation" value="classpath:spring/mybatis-configuration.xml"/>
        </bean>
    </beans>

    第四步:applicationContext-tx.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"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/aop
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
            http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
        <aop:aspectj-autoproxy/>
    
        <tx:annotation-driven transaction-manager="transactionManager" />
    
        <bean id="transactionManager_wms"
              class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource_wms" />
        </bean>
        <bean id="transactionTemplate_wms"  class="org.springframework.transaction.support.TransactionTemplate">
            <property name="transactionManager" ref="transactionManager_wms" />
        </bean>
    
        <bean id="transactionManager_tms"
              class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property name="dataSource" ref="dataSource_tms" />
        </bean>
        <bean id="transactionTemplate_tms"  class="org.springframework.transaction.support.TransactionTemplate">
            <property name="transactionManager" ref="transactionManager_tms" />
        </bean>
    </beans>
  • 相关阅读:
    在Centos 7下编译openwrt+njit-client
    开博随笔
    Chapter 6. Statements
    Chapter 4. Arrays and Pointers
    Chapter 3. Library Types
    Chapter 2.  Variables and Basic Types
    关于stm32不常用的中断,如何添加, 比如timer10 timer11等
    keil 报错 expected an identifier
    案例分析 串口的地不要接到电源上 会烧掉
    案例分析 CAN OPEN 调试记录 进度
  • 原文地址:https://www.cnblogs.com/durp/p/9299209.html
Copyright © 2011-2022 走看看