package eu.dnetlib.usagestats.config; //import org.springframework.boot.jdbc.DataSourceBuilder; 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; import org.apache.log4j.Logger; import org.apache.tomcat.jdbc.pool.PoolProperties; import org.springframework.beans.factory.annotation.Value; /** * Created by tsampikos on 8/3/2017. */ @Configuration public class DataSourceConfiguration { private final Logger log = Logger.getLogger(this.getClass()); @Value("${usagestats.driverClassName}") private String driverClassName; @Value("${usagestats.url}") private String dbURL; @ConfigurationProperties(prefix = "usagestats") @Bean @Primary public DataSource getDataSource() { PoolProperties poolProperties = new PoolProperties(); poolProperties.setUrl(dbURL); poolProperties.setDriverClassName(driverClassName); log.info("dbURL " + dbURL); log.info("driverClassName " + driverClassName); poolProperties.setTestOnBorrow(true); poolProperties.setValidationQuery("SELECT 1"); poolProperties.setValidationInterval(0); DataSource ds = new org.apache.tomcat.jdbc.pool.DataSource(poolProperties); return ds; } }