diff --git a/src/test/java/org/springframework/data/jpa/repository/procedures/MySqlStoredProcedureIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/procedures/MySqlStoredProcedureIntegrationTests.java index 2bde920383..53fccd746b 100644 --- a/src/test/java/org/springframework/data/jpa/repository/procedures/MySqlStoredProcedureIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/procedures/MySqlStoredProcedureIntegrationTests.java @@ -63,6 +63,7 @@ * * @author Gabriel Basilio * @author Greg Turnquist + * @author Yanming Zhou */ @Transactional @ExtendWith(SpringExtension.class) @@ -190,26 +191,21 @@ public interface EmployeeRepositoryWithNoCursor extends JpaRepository MYSQL_CONTAINER; - - @Bean - public DataSource dataSource() { - - if (MYSQL_CONTAINER == null) { - - MYSQL_CONTAINER = new MySQLContainer<>("mysql:8.0.24") // + @SuppressWarnings("resource") + @Bean(initMethod = "start") + public MySQLContainer container() { + return new MySQLContainer<>("mysql:8.0.24") // .withUsername("test") // .withPassword("test") // .withConfigurationOverride(""); - MYSQL_CONTAINER.start(); - } + } + @Bean + public DataSource dataSource(MySQLContainer container) { MysqlDataSource dataSource = new MysqlDataSource(); - dataSource.setUrl(MYSQL_CONTAINER.getJdbcUrl()); - dataSource.setUser("root"); - dataSource.setPassword(MYSQL_CONTAINER.getPassword()); - dataSource.setDatabaseName(MYSQL_CONTAINER.getDatabaseName()); - + dataSource.setUrl(container.getJdbcUrl()); + dataSource.setUser(container.getUsername()); + dataSource.setPassword(container.getPassword()); return dataSource; } diff --git a/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java index ae6b42366e..b67a53b6f2 100644 --- a/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/procedures/PostgresStoredProcedureIntegrationTests.java @@ -65,6 +65,7 @@ * * @author Gabriel Basilio * @author Greg Turnquist + * @author Yanming Zhou */ @Transactional @ExtendWith(SpringExtension.class) @@ -193,23 +194,19 @@ public interface EmployeeRepositoryWithRefCursor extends JpaRepository POSTGRESQL_CONTAINER; + @SuppressWarnings("resource") + @Bean(initMethod = "start") + public PostgreSQLContainer container() { + return new PostgreSQLContainer<>("postgres:9.6.12") // + .withUsername("postgres"); + } @Bean - public DataSource dataSource() { - - if (POSTGRESQL_CONTAINER == null) { - - POSTGRESQL_CONTAINER = new PostgreSQLContainer<>("postgres:9.6.12") // - .withUsername("postgres"); - POSTGRESQL_CONTAINER.start(); - } - + public DataSource dataSource(PostgreSQLContainer container) { PGSimpleDataSource dataSource = new PGSimpleDataSource(); - dataSource.setUrl(POSTGRESQL_CONTAINER.getJdbcUrl()); - dataSource.setUser(POSTGRESQL_CONTAINER.getUsername()); - dataSource.setPassword(POSTGRESQL_CONTAINER.getPassword()); - + dataSource.setUrl(container.getJdbcUrl()); + dataSource.setUser(container.getUsername()); + dataSource.setPassword(container.getPassword()); return dataSource; }