spring配置动态数据源 一定要指定默认的数据源么



 <!-- 配置动态数据源 -->
    <bean id="dynamicDataSource" class="me.ele.coffee.mkt.utp.utils.DynamicDataSourceUtils" >  
        <!-- 通过key-value的形式来关联数据源 -->  
        <property name="targetDataSources">  
            <map>  
                <entry value-ref="slave1DataSource" key="slave1DataSource"></entry>  
                <entry value-ref="slave2DataSource" key="slave2DataSource"></entry>  
            </map>  
        </property>  
        <property name="defaultTargetDataSource" ref="slave1DataSource" />  
    </bean>  

    <bean id="slaveJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource">
            <ref bean="dynamicDataSource" />
        </property>
    </bean>

我的dao中注入slaveJdbcTemplate 可是每次调用的都是defaultTargetDataSource指定的数据源 怎么可以随机选择不同的数据源

谢谢

spring java jdbcTemplate

寻找赵旭俊 9 years, 4 months ago

Your Answer