package <%=packageName%>.config;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;<% if (hibernateCache == 'hazelcast') { %>
import org.springframework.cache.CacheManager;<% } %>
import org.springframework.boot.bind.RelaxedPropertyResolver;
import org.springframework.context.ApplicationContextException;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.*;
import org.springframework.core.env.Environment;

import javax.sql.DataSource;
import java.net.URI;
import java.net.URISyntaxException;

@Configuration
@Profile(Constants.SPRING_PROFILE_HEROKU)
public class HerokuDatabaseConfiguration implements EnvironmentAware {

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

    private RelaxedPropertyResolver dataSourcePropertyResolver;

    private RelaxedPropertyResolver jhipsterPropertyResolver;

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

    @Bean
    public DataSource dataSource(<% if (hibernateCache == 'hazelcast') { %>CacheManager cacheManager<% } %>) {
        log.debug("Configuring Heroku Datasource");

        String herokuUrl = System.getenv("JDBC_DATABASE_URL");
        if (herokuUrl != null) {
	    HikariConfig config = new HikariConfig();

	    //MySQL optimizations, see https://github.com/brettwooldridge/HikariCP/wiki/MySQL-Configuration
	    if ("com.mysql.jdbc.jdbc2.optional.MysqlDataSource".equals(dataSourcePropertyResolver.getProperty("driver-class-name"))) {
                config.addDataSourceProperty("cachePrepStmts", jhipsterPropertyResolver.getProperty("cachePrepStmts", "true"));
                config.addDataSourceProperty("prepStmtCacheSize", jhipsterPropertyResolver.getProperty("prepStmtCacheSize", "250"));
                config.addDataSourceProperty("prepStmtCacheSqlLimit", jhipsterPropertyResolver.getProperty("prepStmtCacheSqlLimit", "2048"));
            }

            config.setDataSourceClassName(dataSourcePropertyResolver.getProperty("driver-class-name"));
            config.addDataSourceProperty("url", herokuUrl);
            return new HikariDataSource(config);
        } else {
            throw new ApplicationContextException("Heroku database URL is not configured, you must set $JDBC_DATABASE_URL");
        }
    }
}

@@ -165,16 +165,89 @@
 Factory;
+%0Aimport org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
 %3C%25 if (h
@@ -339,70 +339,8 @@
  %25%3E%0A
-import org.springframework.boot.bind.RelaxedPropertyResolver;%0A
 impo
@@ -438,209 +438,50 @@
 ext.
-EnvironmentAware;%0Aimport org.springframework.context.annotation.*;%0Aimport org.springframework.core.env.Environment;%0A%0Aimport javax.sql.DataSource;%0Aimport java.net.URI;%0Aimport java.net.URISyntaxException
+annotation.*;%0A%0Aimport javax.sql.DataSource
 ;%0A%0A@
@@ -581,36 +581,8 @@
 ion 
-implements EnvironmentAware 
 %7B%0A%0A 
@@ -680,466 +680,127 @@
     
-private RelaxedPropertyResolver dataSourcePropertyResolver;%0A%0A    private RelaxedPropertyResolver jhipsterPropertyResolver;%0A%0A    @Override%0A    public void setEnvironment(Environment environment) %7B%0A        this.dataSourcePropertyResolver = new RelaxedPropertyResolver(environment, %22spring.datasource.%22);%0A        this.jhipsterPropertyResolver = new RelaxedPropertyResolver(environment, %22jhipster.datasource.%22);%0A    %7D%0A%0A    @Bean%0A    public DataSource dataSource(
+@Bean%0A    public DataSource dataSource(DataSourceProperties dataSourceProperties, JHipsterProperties jHipsterProperties
 %3C%25 i
@@ -837,16 +837,18 @@
 t') %7B %25%3E
+, 
 CacheMan
@@ -1258,49 +1258,31 @@
 pert
-yResolver.getProperty(%22d
+ies.getD
 river
--c
+C
 lass
--name%22
+Name(
 ))) 
@@ -1343,25 +1343,25 @@
 repStmts%22, j
-h
+H
 ipsterProper
@@ -1365,32 +1365,31 @@
 pert
-yResolver.getProperty(%22c
+ies.getDatasource().isC
 ache
@@ -1401,17 +1401,9 @@
 tmts
-%22, %22true%22
+(
 ));%0A
@@ -1465,25 +1465,25 @@
 acheSize%22, j
-h
+H
 ipsterProper
@@ -1487,32 +1487,32 @@
 pert
-yResolver.getProperty(%22p
+ies.getDatasource().getP
 repS
@@ -1527,16 +1527,9 @@
 Size
-%22, %22250%22
+(
 ));%0A
@@ -1599,17 +1599,17 @@
 imit%22, j
-h
+H
 ipsterPr
@@ -1617,32 +1617,32 @@
 pert
-yResolver.getProperty(%22p
+ies.getDatasource().getP
 repS
@@ -1661,17 +1661,9 @@
 imit
-%22, %222048%22
+(
 ));%0A
@@ -1740,49 +1740,31 @@
 pert
-yResolver.getProperty(%22d
+ies.getD
 river
--c
+C
 lass
--name%22
+Name(
 ));%0A

Update the Heroku sub-generator to use the new Spring configuration meta-data