content: package com.urunov.configure;
  
  import com.urunov.ShoppingApplication;
  import com.zaxxer.hikari.HikariConfig;
  import com.zaxxer.hikari.HikariDataSource;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  import org.springframework.orm.jpa.JpaTransactionManager;
  import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  import org.springframework.transaction.PlatformTransactionManager;
  import org.springframework.transaction.annotation.EnableTransactionManagement;
  import org.springframework.transaction.annotation.TransactionManagementConfigurer;
  
  import java.util.Properties;
  
  /**
   * User: hamdamboy
   * Project: Shopping
   * Github: @urunov
   */
  @Configuration
  @EnableAutoConfiguration
  @EnableTransactionManagement
  @EnableJpaRepositories(basePackageClasses = ShoppingApplication.class)
  public class JpaConfig implements TransactionManagementConfigurer {
  
  
      @Value("${dataSource.driverClassName}")
      private String driver;
      @Value("${dataSource.url}")
      private String url;
      @Value("${dataSource.username}")
      private String username;
      @Value("${dataSource.password}")
      private String password;
      @Value("${hibernate.dialect}")
      private String dialect;
      @Value("${hibernate.hbm2ddl.auto}")
      private String hbm2ddlAuto;
      @Value("${spring.datasource.maximumPoolSize}")
      private int maximumPoolSize;
  
      @Bean
      public HikariDataSource configureDataSource()
      {
          HikariConfig config = new HikariConfig();
          config.setDriverClassName(driver);
          config.setJdbcUrl(url);
          config.setUsername(username);
          config.setPassword(password);
          config.setMaximumPoolSize(maximumPoolSize);
          config.setConnectionTimeout(60000);
          config.setIdleTimeout(60000);
          config.setLeakDetectionThreshold(60000);
          return new HikariDataSource(config);
      }
  
      @Bean(name = "entityManagerFactory")
      public LocalContainerEntityManagerFactoryBean configureEntityManagerFactory()
      {
          LocalContainerEntityManagerFactoryBean entityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
          entityManagerFactoryBean.setDataSource(configureDataSource());
          entityManagerFactoryBean.setPackagesToScan("com.urunov");
          entityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
          Properties jpaProperties = new Properties();
          jpaProperties.put(org.hibernate.cfg.Environment.DIALECT, dialect);
          jpaProperties.put(org.hibernate.cfg.Environment.HBM2DDL_AUTO, hbm2ddlAuto);
          entityManagerFactoryBean.setJpaProperties(jpaProperties);
          return entityManagerFactoryBean;
      }
  
      @Bean(name = "transactionManager")
      public PlatformTransactionManager annotationDrivenTransactionManager()
      {
          return new JpaTransactionManager();
      }
  
  }
  