使用idea开发软件实现springboot热部署:
1、添加依赖,在pom.xml文件中添加依赖
<!--热部署--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <optional>true</optional> </dependency>
2、启动自动编译,打钩 File/settings/Compiler/Build Project autoMatically
3、选择Tomcat的 On 'Update' action 和 On frame deactivation 的选项为 '更新类和资源'
4、ctrl + shift + alt + /,选择Registry,勾上 Compiler autoMake allow when app running
到此为止,既已经实现了热部署,在更该页面和后台代码时,只需刷新页面即可,不需再重新启动服务器,
测试
- 修改类–>保存:应用会重启
- 修改配置文件–>保存:应用会重启
- 修改页面–>保存:应用不会重启,但会重新加载,页面会刷新(原理是将spring.thymeleaf.cache设为false,参考:Spring Boot配置模板引擎)