content: package com.alibaba.tesla.appmanager.spring.config;
  
  import com.zaxxer.hikari.HikariConfig;
  import com.zaxxer.hikari.HikariDataSource;
  import lombok.extern.slf4j.Slf4j;
  import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
  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;
  
  import javax.sql.DataSource;
  
  @Configuration
  @Slf4j
  public class DatasourceConfig {
  
      @Bean
      @Primary
      @ConfigurationProperties("spring.datasource")
      public DataSourceProperties mySQLDataSourceProperties() {
          return new DataSourceProperties();
      }
  
      @Bean
      @Primary
      @ConfigurationProperties("spring.datasource.hikari")
      public DataSource mySQLDataSource() {
          return mySQLDataSourceProperties().initializeDataSourceBuilder().build();
      }
  
      @Bean
      @ConfigurationProperties(prefix = "spring.datasource.hikari")
      public HikariConfig hikariConfig() {
          HikariConfig config = new HikariConfig();
          config.setExceptionOverrideClassName(DatasourceExceptionConfig.class.getCanonicalName());
          return config;
      }
  
      @Bean
      public DataSource dataSource() {
          return new HikariDataSource(hikariConfig());
      }
  }
  