Spring boot Druid 多数据源JDBC和注解事务

1.引入依赖

gradle文件配置,用maven引入也可以

runtimeOnly 'com.microsoft.sqlserver:mssql-jdbc' //数据库驱动
implementation 'org.springframework.boot:spring-boot-starter-jdbc' //spring jdbc
implementation 'com.alibaba:druid-spring-boot-starter:1.1.10' //连接池

2.配置类

DataSourceConfig.java

package com.example;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransaction

你可能感兴趣的:(多数据源,druid,spring,事务,jdbc)