В сообщении об ошибке говорится:
Код: Выделить всё
Message: Connection to localhost:32868 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Код: Выделить всё
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Failed to initialize dependency 'flywayInitializer' of LoadTimeWeaverAware bean 'entityManagerFactory': Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Unable to obtain connection from database: Connection to localhost:32868 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
Код: Выделить всё
@Testcontainers
@SpringBootTest
@AutoConfigureMockMvc
public class OwnerRestControllerTest {
// Ideally, the container should be recognized as "in use"
@Container
@ServiceConnection
static PostgreSQLContainer postgresContainer =
new PostgreSQLContainer(DockerImageName.parse("postgres:17-alpine"));
@Autowired
private MockMvc mockMvc;
@Autowired
private OwnerRepository ownerRepository;
@Test
@Sql(scripts = "classpath:insert-owners.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(scripts = "classpath:delete-owners.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public void getAll() throws Exception {
mockMvc.perform(get("/rest/owners")
.param("lastNameContains", "Doe"))
.andExpect(status()
.isOk())
.andExpect(jsonPath("$.content[*].lastName").value(everyItem(is("Doe"))))
.andExpect(jsonPath("$.content.length()").value(2));
}
}
Код: Выделить всё
@Testcontainers
@SpringBootTest
@AutoConfigureMockMvc
public class OwnerRestControllerTest {
@BeforeAll
static void beforeAll() throws InterruptedException {
Thread.sleep(5000);
}
}
Вы можете запустить приложение из этой ветки: Репозиторий GitHub.
Есть ли другой подход? следует использовать для настройки среды с помощью Testcontainers и Flyway? Или это просто ошибка?
Подробнее здесь: https://stackoverflow.com/questions/791 ... and-flyway