Skip to content

Instantly share code, notes, and snippets.



Created Sep 3, 2018
What would you like to do?
* the db spring configuration to use in production , to be replaced with actual production configuration , that is for local run only
public class DbConfig {
private static final List<String> DEFAULT_ADDITIONAL_INIT_DB_PARAMS = Arrays
.asList("--nosync", "--locale=en_US.UTF-8");
* @param config the PostgresConfig configuration which will be used to get the needed host, port..
* @return the created DB datasource
public DataSource dataSource(PostgresConfig config) {
DriverManagerDataSource ds = new DriverManagerDataSource();
return ds;
* @return PostgresConfig that contains embedded db configuration like user name , password
* @throws IOException
public PostgresConfig postgresConfig() throws IOException {
// make it readable from configuration source file or system , it is hard coded here for explanation purpose only
final PostgresConfig postgresConfig = new PostgresConfig(Version.V9_6_8,
new AbstractPostgresConfig.Net("localhost", Network.getFreeServerPort()),
new AbstractPostgresConfig.Storage("test"),
new AbstractPostgresConfig.Timeout(),
new AbstractPostgresConfig.Credentials("user", "pass")
return postgresConfig;
* @param config the PostgresConfig configuration to use to start Postgres db process
* @return PostgresProcess , the started db process
* @throws IOException
@Bean(destroyMethod = "stop")
public PostgresProcess postgresProcess(PostgresConfig config) throws IOException {
PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getDefaultInstance();
PostgresExecutable exec = runtime.prepare(config);
PostgresProcess process = exec.start();
return process;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.