Skip to content

tanghuibo/spring-multiple-mybatis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

springboot 多数据源配置

配置步骤

使用 SQLSessionFactoryInjection 注入 DataSource, SqlSessionFactory, SqlSessionTemplate

事例

@Configuration
@SQLSessionFactoryInjection(name = "one")
public class OneSessionFactoryConfig {
}

配置信息

spring:
  datasource:
    one:
      url: jdbc:mysql://localhost:3306/mysql_emoji_test
      username: root
      password: 123456
      driver-class-name: com.mysql.cj.jdbc.Driver
      type: org.springframework.jdbc.datasource.SimpleDriverDataSource
mybatis:
  one:
    mapper-locations: classpath:mapping/one/**Mapper.xml

得到 oneDataSource, oneSqlSessionFactory, oneSqlSessionTemplate

使用 MapperScan 注入 mapper

事例

@Configuration
@MapperScan(basePackages = "io.tanghuibo.github.springmultiplemybatis.mapper.one", sqlSessionTemplateRef = "oneSqlSessionTemplate")
public class MybatisConfig {
}

得到 oneMapper

About

spring 多数据源配置

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages