步骤很简单,只需要变更一下pom文件。
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会认为这是生产环境而自动失效

本文介绍了如何使用Spring Boot DevTools实现项目的热加载功能。通过在pom文件中添加依赖,可以实现在修改代码并保存后自动重启应用的效果。Eclipse环境中保存文件即可触发热加载,而在IDEA中则需通过快捷键Ctrl+F9手动触发。
1685

被折叠的 条评论
为什么被折叠?



