Spring Boot实现热加载(Eclipse,IDEA)

步骤很简单,只需要变更一下pom文件。

首先贴上官方文档介绍:
https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/html/using-boot-devtools.html#using-boot-devtools-restart

1. Maven添加依赖

将下边的依赖添加到你的pom文件中去

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

2. 实现热加载

  • Eclipse中,保存文件会自动触发热加载
  • IDEA中,需要build project来触发热加载,快捷键是Ctrl+F9

官方文档:As DevTools monitors classpath resources, the only way to trigger a restart is to update the classpath. The way in which you cause the classpath to be updated depends on the IDE that you are using. In Eclipse, saving a modified file causes the classpath to be updated and triggers a restart. In IntelliJ IDEA, building the project (Build -> Build Project) has the same effect.

3. 注意

  • 如果你的项目是通过java命令(java -jar)或者某个特殊的类加载器启动的,spring-boot 的Developer tools会认为这是生产环境而自动失效

版权声明:本文为LIsmooth原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。