架构师之路--spring多数据源和mybatis多数据源配置

从数据源配置文件

原有数据源不变动下,新增配置文件

<?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:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

	<!-- ========================================配置数据源========================================= -->
	<!-- crm数据源的配置 -->
	<bean id="dataSourceCrm" class="com.alibaba.druid.pool.DruidDataSource"
		  init-method="init" destroy-method="close">
		<property name="driverClassName" value="${jdbc.crm.driver}" />
		<property name="url" value="${jdbc.crm.url}" />
		<property name="username" value="${jdbc.crm.username}" />
		<property name="password" value="${jdbc.crm.password}" />
		<property name="initialSize" value="20" />
		<property name="maxActive" value="500" />
		<property name="minIdle" value="3" />

		<property name="removeAbandoned" value="true" />
		<property name="testOnBorrow" value="false" />
		<property name="testWhileIdle" value="true" />
		<property name="testOnReturn" value="false" />

		<property name="removeAbandonedTimeout" value="600" />
		<property name="maxWait" value="60000" />
		<property name="validationQuery" value="SELECT 1" />
		<property name="timeBetweenEvictionRunsMillis" value="3600000" />
		<property name="minEvictableIdleTimeMillis" value="3600000" />
	</bean>
	<!-- ========================================针对myBatis的配置项============================== -->
	<!-- 配置扫描器 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<property name="basePackage" value="com.qunji.sale.console.batch.crm" />
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactorytwo" />
	</bean>
	<!-- 配置sqlSessionFactorytwo -->
	<bean id="sqlSessionFactorytwo" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="configLocation" value="classpath:mybatis/SqlCrmMapConfig.xml" />
		<property name="dataSource" ref="dataSourceCrm" />
		<property name="mapperLocations" value="classpath:mapping/crm/*.xml" />
	</bean>
</beans>

注意的问题

1.保证主数据源扫描的dao,和从数据源扫描的dao不能重复
2.关于事务问题要注意,最好默认主数据源,有特殊需求则修改配置

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值