package <%=packageName%>.config;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import liquibase.integration.spring.SpringLiquibase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableJpaRepositories("<%=packageName%>.repository")
@EnableTransactionManagement
public class DatabaseConfiguration implements EnvironmentAware {

    private final Logger log = LoggerFactory.getLogger(DatabaseConfiguration.class);

    private RelaxedPropertyResolver env;

    @Override
    public void setEnvironment(Environment environment) {
        this.env = new RelaxedPropertyResolver(environment, "spring.datasource.");
    }

    @Bean
    public DataSource dataSource() {
        log.debug("Configuring Datasource");
        HikariConfig config = new HikariConfig();
        config.setDataSourceClassName(env.getProperty("dataSourceClassName"));
        if (env.getProperty("url") == null || "".equals(env.getProperty("url"))) {
            config.addDataSourceProperty("databaseName", env.getProperty("databaseName"));
            config.addDataSourceProperty("serverName", env.getProperty("serverName"));
        } else {
            config.addDataSourceProperty("url", env.getProperty("url"));
        }
        config.addDataSourceProperty("user", env.getProperty("username"));
        config.addDataSourceProperty("password", env.getProperty("password"));
        return new HikariDataSource(config);
    }

    @Bean(name = {"org.springframework.boot.autoconfigure.AutoConfigurationUtils.basePackages"})
    public List<String> getBasePackages() {
        List<String> basePackages = new ArrayList<String>();
        basePackages.add("<%=packageName%>.domain");
        return basePackages;
    }

    @Bean
    public SpringLiquibase liquibase() {
        log.debug("Configuring Liquibase");
        SpringLiquibase liquibase = new SpringLiquibase();
        liquibase.setDataSource(dataSource());
        liquibase.setChangeLog("classpath:config/liquibase/db-changelog.xml");
        liquibase.setContexts("development, production");
        return liquibase;
    }
}


@@ -277,24 +277,88 @@
 tyResolver;%0A
+import org.springframework.context.ApplicationContextException;%0A
 import org.s
@@ -717,16 +717,44 @@
 ement;%0A%0A
+import javax.inject.Inject;%0A
 import j
@@ -1112,16 +1112,71 @@
 esolver 
+propertyResolver;%0A%0A    @Inject%0A    private Environment 
 env;%0A%0A  
@@ -1258,19 +1258,32 @@
    this.
-env
+propertyResolver
  = new R
@@ -1436,24 +1436,499 @@
 tasource%22);%0A
+        if (propertyResolver.getProperty(%22url%22) == null && propertyResolver.getProperty(%22databaseName%22) == null) %7B%0A            log.error(%22Your database connection pool configuration is incorrect! The application%22 +%0A                    %22cannot start. Please check your Spring profile, current profiles are: %7B%7D%22,%0A                    env.getActiveProfiles());%0A%0A            throw new ApplicationContextException(%22Database connection pool is not configured correctly%22);%0A        %7D%0A
         Hika
@@ -2003,19 +2003,32 @@
 assName(
-env
+propertyResolver
 .getProp
@@ -2069,19 +2069,32 @@
     if (
-env
+propertyResolver
 .getProp
@@ -2126,19 +2126,32 @@
 .equals(
-env
+propertyResolver
 .getProp
@@ -2219,27 +2219,40 @@
 abaseName%22, 
-env
+propertyResolver
 .getProperty
@@ -2325,19 +2325,32 @@
 rName%22, 
-env
+propertyResolver
 .getProp
@@ -2435,19 +2435,32 @@
 (%22url%22, 
-env
+propertyResolver
 .getProp
@@ -2528,19 +2528,32 @@
 %22user%22, 
-env
+propertyResolver
 .getProp
@@ -2620,19 +2620,32 @@
 sword%22, 
-env
+propertyResolver
 .getProp

Check connection pool configuration and throw error message if it’s not correct