You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using spring-boot-3.1.0-SNAPSHOT with Spring Data JPA, Postgres, Testcontainers.
For local development, I have created TestcontainersConfiguration.java and TestApplication.java under src/test/java as follows:
@TestConfiguration(proxyBeanMethods = false)
public class TestcontainersConfiguration {
@Bean
@ServiceConnection
public PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>("postgres:15.2-alpine");
}
}
public class TestApplication {
public static void main(String[] args) {
SpringApplication
.from(Application::main)
.with(TestcontainersConfiguration.class)
.run(args);
}
}
When I run TestApplication.java from IDE then Testcontainers is starting the Postgres database and application is working fine.
Problem:
But, if I add spring-boot-devtools dependency and run TestApplication.java then Testcontainers integration is stopped working. ie, Postgres container is not being started and application startup is failing.
Thanks for trying the snapshots @sivaprasadreddy, and thanks @eddumelendez for tracking down the commit. I think I know what's causing this. There's a bug in org.springframework.boot.devtools.restart.MainMethod where it stops at the first main that it finds rather than the last. This means that the app gets restarted with Application.main rather than TestApplication.main. Before fixing #35206, the restarted app would find the configuration because of @ComponentScan.
philwebb
changed the title
SpringBoot Testcontainers Local Development support is not working when devtools is added
Devtools main method search algorithm can find incorrect main method
May 1, 2023
I am using spring-boot-3.1.0-SNAPSHOT with Spring Data JPA, Postgres, Testcontainers.
For local development, I have created
TestcontainersConfiguration.java
andTestApplication.java
undersrc/test/java
as follows:When I run TestApplication.java from IDE then Testcontainers is starting the Postgres database and application is working fine.
Problem:
But, if I add
spring-boot-devtools
dependency and run TestApplication.java then Testcontainers integration is stopped working. ie, Postgres container is not being started and application startup is failing.Reproducer: https://github.com/sivaprasadreddy/spring-boot-testcontainers-devmode
In pom.xml uncomment
spring-boot-devtools
dependency and run to reproduce the problem.The text was updated successfully, but these errors were encountered: