title: Creating custom connection pool in Spring Boot application
body: <p>I'm writing a Spring Boot application which connects with Snowflake Data Warehouse and execute SQL queries on it.
  I have written a Configuration class for configuring Datasource for connecting to Snowflake Data Warehouse as follows:</p>
  
  <pre><code>@Configuration
  @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
  public class DBConfig {
  
      Logger logger = LoggerFactory.getLogger(DBConfig.class);
      @Bean
      JdbcTemplate jdbcTemplate() throws IllegalAccessException, InvocationTargetException, InstantiationException {
          logger.info("-----Configuring JDBCTemplate------");
          SnowflakeBasicDataSource dataSource = new SnowflakeBasicDataSource();
          dataSource.setServerName("&lt;myserver&gt;.snowflakecomputing.com");
          dataSource.setUser("&lt;my_username&gt;");
          dataSource.setPassword("&lt;my_password&gt;");
          dataSource.setWarehouse("DEMO_WH");
          dataSource.setDatabaseName("DEMO_DB");
          dataSource.setSchema("PUBLIC");
          return new JdbcTemplate(dataSource);
      }
  }
  </code></pre>
  
  <p>My pom.xml looks like as follows:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.1.1.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.vaibhav&lt;/groupId&gt;
      &lt;artifactId&gt;snowflake-1&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;snowflake-1&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;properties&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.snowflake&lt;/groupId&gt;
              &lt;artifactId&gt;snowflake-jdbc&lt;/artifactId&gt;
              &lt;version&gt;3.6.21&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web-services&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  
  <p>I have to use a connection pool for this data source in my Spring boot application.</p>
  
  <p>How can I use HikariCP connection pool in my application which can work perfectly fine with my Customized DataSource?</p>
  
  <p><strong>------EDIT --- Thanks for providing solution, finally my working code looks like</strong></p>
  
  <pre><code>@Configuration
  @EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
  public class DBConfig {
  
      Logger logger = LoggerFactory.getLogger(DBConfig.class);
  
      @Bean
      JdbcTemplate jdbcTemplate() throws IllegalAccessException, InvocationTargetException, InstantiationException {
          logger.info("-----Configuring JDBCTemplate------");
  
          HikariConfig config = new HikariConfig();
          config.setDriverClassName("net.snowflake.client.jdbc.SnowflakeDriver");
          // config.setDataSourceProperties(properties);
          config.setJdbcUrl("jdbc:snowflake://&lt;myserver&gt;.snowflakecomputing.com/?warehouse=DEMO_WH&amp;db=DEMO_DB&amp;schema=PUBLIC");
          config.setUsername("&lt;my_username&gt;");
          config.setPassword("&lt;my_password&gt;");
          HikariDataSource ds = new HikariDataSource(config);
  
          return new JdbcTemplate(ds);
      }
  }
  </code></pre>