Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devtools main method search algorithm can find incorrect main method #35214

Closed
sivaprasadreddy opened this issue May 1, 2023 · 2 comments
Closed
Labels
type: bug A general bug
Milestone

Comments

@sivaprasadreddy
Copy link

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.

Reproducer: https://github.com/sivaprasadreddy/spring-boot-testcontainers-devmode

In pom.xml uncomment spring-boot-devtools dependency and run to reproduce the problem.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 1, 2023
@eddumelendez
Copy link
Contributor

According to my local tests. It was broken via this commit 2b261e6 when using spring-boot-devtools

@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 1, 2023
@philwebb philwebb added this to the 3.1.x milestone May 1, 2023
@philwebb philwebb added the theme: containers Testcontainers and Docker Compose features label May 1, 2023
@philwebb
Copy link
Member

philwebb commented May 1, 2023

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 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
@philwebb philwebb removed the theme: containers Testcontainers and Docker Compose features label May 1, 2023
@philwebb philwebb modified the milestones: 3.1.x, 2.7.x May 1, 2023
@philwebb philwebb modified the milestones: 2.7.x, 2.7.12 May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants