Я столкнулся с проблемой при запуске интеграционных тестов в приложении Spring Boot с использованием JUnit 5 и Testcontainers. Несмотря на соблюдение рекомендаций по настройке, мои тесты не запускаются из-за исключения создания компонента, связанного с подключением к базе данных.
Зависимости:
Я используя Testcontainers версии 1.19.3 со следующими зависимостями в моем pom.xml:
Код: Выделить всё
1.19.3
org.testcontainers
junit-jupiter
${testcontainers.version}
test
junit
junit
org.testcontainers
postgresql
${testcontainers.version}
test
Код: Выделить всё
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:tc:postgresql:10.4://localhost:5432/test-tc
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
username: postgres
password: postgres
**
Код: Выделить всё
package com.worldline.ancv.messagebroker.web.rest;
import com.worldline.ancv.messagebroker.MessageBrokerApp;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest(classes = MessageBrokerApp.class)
public class TestOff {
@Test
public void getAllLogs() {
// Test implementation
}
}
Код: Выделить всё
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'batchDataSourceInitializer' defined in class path resource [org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration$DataSourceInitializerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.batch.BatchDataSourceScriptDatabaseInitializer]: Factory method 'batchDataSourceInitializer' threw exception; nested exception is java.lang.IllegalStateException: Failed to determine DatabaseDriver
...
Caused by: java.sql.SQLException: HikariDataSource HikariDataSource (HikariPool-9) has been closed.
Источник: https://stackoverflow.com/questions/781 ... -to-launch