Skip to content

Instantly share code, notes, and snippets.

@Romeh
Created March 6, 2019 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Romeh/ff32ad219e88f5fa2d4a8c7abdb4e37f to your computer and use it in GitHub Desktop.
Save Romeh/ff32ad219e88f5fa2d4a8c7abdb4e37f to your computer and use it in GitHub Desktop.
@Bean
public DataSource dataSource() {
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("org.postgresql.Driver");
// here we reference the static test container variable in our test case to get the used the connection details
ds.setUrl(format("jdbc:postgresql://%s:%s/%s", postgreSQLContainer.getContainerIpAddress(),
postgreSQLContainer.getMappedPort(
PostgreSQLContainer.POSTGRESQL_PORT), postgreSQLContainer.getDatabaseName()));
ds.setUsername(postgreSQLContainer.getUsername());
ds.setPassword(postgreSQLContainer.getPassword());
ds.setSchema(postgreSQLContainer.getDatabaseName());
return ds;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment