Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package app.config; import java.net.URISyntaxException; import org.apache.commons.dbcp2.BasicDataSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @Configuration @Profile("production") public class DatabaseConfig { @Bean public BasicDataSource dataSource() throws URISyntaxException { String dbUrl = System.getenv("JDBC_DATABASE_URL"); String username = System.getenv("JDBC_DATABASE_USERNAME"); String password = System.getenv("JDBC_DATABASE_PASSWORD"); BasicDataSource basicDataSource = new BasicDataSource(); basicDataSource.setUrl(dbUrl); basicDataSource.setUsername(username); basicDataSource.setPassword(password); return basicDataSource; } }