为什么 spring boot devtools 两次调用 main 方法?

mrt*_*sln 6 spring-boot spring-boot-devtools

我在我的项目中使用 spring boot devtools。当我写

System.out.println("test");
Run Code Online (Sandbox Code Playgroud)

在 main 之前,它在控制台中打印两次。

public static void main(String[] args) {

    System.out.println("test");
    SpringApplication.run(TestApplication.class, args);
}
Run Code Online (Sandbox Code Playgroud)

当我删除

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

在 pom.xml 文件中,它打印一次

小智 7

不仅是两次,如果spring上下文需要刷新,还会再运行一次。

我相信这是一种设计好的行为。

开发工具会自动刷新上下文,而不是手动重新启动。