package com.holytax.accenture_fp_in.datasource;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**

  • 配置多数据源
  • */br/>@Configuration
    public class MultiDataSourceConfig {

    @Bean(name = "primaryDataSource")br/>@Qualifier("primaryDataSource")
    @Primary // 定义主数据源
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource primaryDataSource() {
    return DataSourceBuilder.create().build();
    }

    @Bean(name = "secondaryDataSource")br/>@Qualifier("secondaryDataSource")
    @ConfigurationProperties(prefix = "custom.datasource.ds1")
    public DataSource secondaryDataSource() {
    return DataSourceBuilder.create().build();
    }
    }
    复制代码