Why spring boot devtools called main method twice?

1.4k Views Asked by At

I'm using spring boot devtools with my project. When i write

System.out.println("test");

before main, it printing twice in console.

public static void main(String[] args) {

    System.out.println("test");
    SpringApplication.run(TestApplication.class, args);
}

When i remove

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>

in pom.xml file,it printing once

1

There are 1 best solutions below

1
On

Not only twice, if the spring context need to be refreshed, it will run once more.

I believe it is a designed behavior.

The devtools auto-refresh the context instead of restarting manually.