SpringBot添加多数据源mysql的验证方法
更新:HHH   时间:2023-1-7


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;

/**

  • 配置多数据源
  • */@Configuration
    br/>@Configuration

    @Bean(name = "primaryDataSource")@Qualifier("primaryDataSource")
    br/>@Qualifier("primaryDataSource")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource primaryDataSource() {
    return DataSourceBuilder.create().build();
    }

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

返回云计算教程...