SpringBoot热部署

使用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配置模板引擎)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章