zoukankan      html  css  js  c++  java
  • 多数据源配置(Spring+mybatis)

    配置流程:

     配置datasource

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
            destroy-method="close">
            <property name="driverClass">
                <value>#[dsp.jdbc.driverClassName]</value>
            </property>
            <property name="jdbcUrl">
                <value>#[dsp.jdbc.url]</value>
            </property>
            <property name="user">
                <value>#[dsp.jdbc.username]</value>
            </property>
            <property name="password">
                <value>#[dsp.jdbc.password]</value>
            </property>
            <property name="maxPoolSize">
                <value>#[dsp.jdbc.maxPoolSize]</value>
            </property>
            <property name="minPoolSize">
                <value>#[dsp.jdbc.minPoolSize]</value>
            </property>
            <property name="initialPoolSize">
                <value>#[dsp.jdbc.initialPoolSize]</value>
            </property>
            <property name="idleConnectionTestPeriod">
                <value>#[dsp.jdbc.idleConnectionTestPeriod]</value>
            </property>
            <property name="maxIdleTime">
                <value>#[dsp.jdbc.maxIdleTime]</value>
            </property>
        </bean>
    <bean id="dataSourceSsp" class="com.mchange.v2.c3p0.ComboPooledDataSource"
              destroy-method="close">
            <property name="driverClass">
                <value>#[ssp.jdbc.driverClassName]</value>
            </property>
            <property name="jdbcUrl">
                <value>#[ssp.jdbc.url]</value>
            </property>
            <property name="user">
                <value>#[ssp.jdbc.username]</value>
            </property>
            <property name="password">
                <value>#[ssp.jdbc.password]</value>
            </property>
            <property name="maxPoolSize">
                <value>#[ssp.jdbc.maxPoolSize]</value>
            </property>
            <property name="minPoolSize">
                <value>#[ssp.jdbc.minPoolSize]</value>
            </property>
            <property name="initialPoolSize">
                <value>#[ssp.jdbc.initialPoolSize]</value>
            </property>
            <property name="idleConnectionTestPeriod">
                <value>#[ssp.jdbc.idleConnectionTestPeriod]</value>
            </property>
            <property name="maxIdleTime">
                <value>#[ssp.jdbc.maxIdleTime]</value>
            </property>
        </bean>

    配置SqlSessionFactory

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"
            lazy-init="false">
            <property name="configLocation" value="classpath:rousseau-mybatis-config.xml"></property>
            <property name="dataSource" ref="dataSource" />
        </bean>
    
    <bean id="sqlSessionFactorySsp" class="org.mybatis.spring.SqlSessionFactoryBean"
              lazy-init="false">
            <property name="configLocation" value="classpath:rousseau-ssp-mybatis-config.xml"></property>
            <property name="dataSource" ref="dataSourceSsp" />
     </bean>

    配置Mapper文件扫描

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="sqlSessionFactory" ref="sqlSessionFactory"/>
            <property name="basePackage" value="com.zmeng.rinascimento.rousseau.mapper.dsp" />
    </bean>
    
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
            <property name="sqlSessionFactory" ref="sqlSessionFactorySsp"/>
            <property name="basePackage" value="com.zmeng.rinascimento.rousseau.mapper.ssp" />
    </bean>
  • 相关阅读:
    FZU-2087 统计树边(最小生成树)
    HDU-1599 find the mincost route(floyd求最小环)
    BZOJ-1191 [HNOI2006]超级英雄Hero(二分图匹配)
    FZU-2020 组合(Lucas定理)
    FZU-2232 炉石传说(二分图匹配)
    NOIP2016模拟 拼接mf(模拟)
    2016年11月10日00:26:08
    BZOJ2986 Non-Squarefree Numbers
    BZOJ3624 [Apio2008]免费道路
    BZOJ3224 Tyvj 1728 普通平衡树
  • 原文地址:https://www.cnblogs.com/shareTechnologyl/p/11686878.html
Copyright © 2011-2022 走看看