springboot+mybatis+Druid配置多数据源(mysql+postgre) springboot+mybatis+Druid配置多数据源(mysql+postgre) 参考资料: 第八章 springboot + mybatis + 多数据源 springboot + mybatis + druid + 多数据源 springBoot 动态数据源以及Mybatis多数据源 springboot - mybatis连接多数据源(动态) 引入pom依赖 org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.1

注入事务的时候需要标明对应数据库(主数据库可以不用设置)

如:db2的数据库的事务"

@Transactional(value = "db2TransactionManager")

mapper层

不同数据库的mapper文件不能载同一个包中,config在注入时会注入错误;

使用时,与单数据源时一致

    @Select("select * from table_1 ")
    public List<Table1> all();
    public List<Table1> all2();
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.cc.commons.mapper.mysql.MysqlMapper">
    <select >
       select * from table_1
    </select>
</mapper>
[{"id1":1,"id2":23,"id3":2222},{"id1":2,"id2":2222,"id3":111}]