当前位置: 首页 > 工具软件 > BeetlSQL > 使用案例 >

SpringBoot-整合Beetlsql及多数据源整理

薛征
2023-12-01

## SpringBoot-整合Beetlsql及多数据源整理

1.引入Beetlsql包
<dependency>
    <groupId>com.ibeetl</groupId>
    <artifactId>beetl-framework-starter-</artifactId>
    <version>1.2.30.RELEASE</version>
</dependency>

2.application.yml配置

(1)数据源配置

spring:

  datasource:

    datasource1:

      jdbc-url: jdbc:oracle:thin:@127.0.0.1:1521/test1

      username: admin

      password: admin

      driver-class-name: oracle.jdbc.OracleDriver

      pool-name: principalHikariCP

    datasource2:

      jdbc-url: jdbc:oracle:thin:@127.0.0.2:1521/test2

      username: admin

      password: admin

      driver-class-name: oracle.jdbc.OracleDriver

      pool-name: principalHikariCP

(2)Beetlsql配置

beetlsql:

ds:

test1:

  basePackage: test1.xxx1.dao

  daoSuffix: DAO

  sqlPath: /sql

  dbStyle: org.beetl.sql.core.UnderlineNameConversion

test2:

  basePackage: test1.xxx2.dao

  daoSuffix: DAO

  sqlPath: /sql

  dbStyle: org.beetl.sql.core.UnderlineNameConversion

#指定数据源

mutiple:

  datasource: datasource1,datasource2

beetl-beetlsql:

  dev: true

3.本地数据源配置类DataSourceConfig.java

@Configuration

public class DataSourceConfig{

@Bean(name="datasource1")

@ConfigurationProperties(prefix="spring.datasource.datasource1")

public DataSource firstDataSource(){

retrun new HikariDataSource();

}

@Bean(name="datasource2")

@ConfigurationProperties(prefix="spring.datasource.datasource2")

public DataSource secondlirDataSource(){

retrun new HikariDataSource();

}

//事务管理器

@Bean

public PlatformTransactionManager firstTransactionManager(@Qualifier("datasource1") DataSource datasource){

return new DataSourceTransactionManager(datasource);

}

@Bean

public PlatformTransactionManager secondTransactionManager(@Qualifier("datasource2") DataSource datasource){

return new DataSourceTransactionManager(datasource);

}

}

 类似资料: