Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why spring boot devtools called main method twice?

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

like image 256
mrtasln Avatar asked May 22 '18 08:05

mrtasln


1 Answers

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.

like image 97
Charles Li Avatar answered Sep 20 '22 07:09

Charles Li