Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@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