spring boot多数据源配置
1.spring.xml里,注入bean
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <import resource="spring-dao-sipserver.xml" /> </beans>
2.spring-dao-sipserver.xml 里配置数据源,其内部的Dao类路径结构,对应起来即可
<?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:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="abstractDataSource-sipserver" abstract="true" class="com.alibaba.druid.pool.DruidDataSource" p:maxActive="9" p:maxWait="10000" p:proxyFilters-ref="druidFilters" /> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer" p:basePackage="com.xxx.dao.api.sipserver" p:sqlSessionFactoryBeanName="sqlSessionFactory-sipserver" /> <bean id="sqlSessionFactory-sipserver" class="org.mybatis.spring.SqlSessionFactoryBean" p:mapperLocations="classpath*:mybatis-mapper-sipserver/*.xml" p:dataSource-ref="dataSource-sipserver" p:plugins-ref="mybatisPlugins" /> <bean id="dataSource-sipserver" parent="abstractDataSource-sipserver" p:url="jdbc:mysql://127.0.0.1:3306/sipserver" p:username="admin" p:password="admin" /> <!-- 事务注解驱动 --> <tx:annotation-driven transaction-manager="transactionManager-sipserver" /> <bean id="transactionManager-sipserver" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" p:dataSource-ref="dataSource-sipserver" /> </beans>
这是5.1.10的
https://blog.csdn.net/wwwkm123/article/details/110518829