content: package com.asyncexcel.springboot.context.mybatisplus;
  
  import com.baomidou.mybatisplus.annotation.IdType;
  import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
  import com.baomidou.mybatisplus.autoconfigure.SpringBootVFS;
  import com.baomidou.mybatisplus.core.config.GlobalConfig;
  import com.baomidou.mybatisplus.core.config.GlobalConfig.DbConfig;
  import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
  import com.zaxxer.hikari.HikariDataSource;
  import javax.sql.DataSource;
  import org.apache.ibatis.mapping.DatabaseIdProvider;
  import org.apache.ibatis.session.SqlSessionFactory;
  import org.mybatis.spring.annotation.MapperScan;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.boot.context.properties.EnableConfigurationProperties;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  
  /**
   * @Description TODO
   * @Author 姚仲杰#80998699
   * @Date 2022/7/5 16:37
   */
  @Configuration
  @MapperScan(value = "com.asyncexcel.springboot.context.mapper",sqlSessionFactoryRef = "excelSqlSessionFactory")
  @EnableConfigurationProperties({ExcelDataSourceProperties.class,MybatisPlusProperties.class})
  public class ExcelMybatisPlusConfiguration {
      
      @Bean("excelDataSource")
      public DataSource dataSource(ExcelDataSourceProperties properties){
          HikariDataSource hikariDataSource = new HikariDataSource();
          hikariDataSource.setJdbcUrl(properties.getUrl());
          hikariDataSource.setUsername(properties.getUsername());
          hikariDataSource.setPassword(properties.getPassword());
          hikariDataSource.setDriverClassName(properties.getDriverClassName());
          return hikariDataSource;
      }
      
      @Bean("excelSqlSessionFactory")
      public SqlSessionFactory sqlSessionFactory(@Qualifier("excelDataSource") DataSource dataSource) throws Exception {
          MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
          mybatisSqlSessionFactoryBean.setVfs(SpringBootVFS.class);
          mybatisSqlSessionFactoryBean.setDataSource(dataSource);
          GlobalConfig globalConfig = new GlobalConfig();
          DbConfig dbConfig = new DbConfig();
          dbConfig.setIdType(IdType.AUTO);
          globalConfig.setDbConfig(dbConfig);
          mybatisSqlSessionFactoryBean.setGlobalConfig(globalConfig);
          return mybatisSqlSessionFactoryBean.getObject();
      }
      
  }
  