Intellij IDEA下Spring Boot热切换配置

相信很多人自己百度“idea springboot 热部署”,找到的解决方案都是如下:

1.项目加入依赖spring-boot-devtools
2.IDEA按ctrl+alt+s——Build,Excution,Deployment——Compiler——勾选Build project automatically
3.IDEA按ctrl+shift+a——输入registry——Compiler——勾选compiler.automake.allow.when.app.running

但其实这样设置,每次你改一点点代码,都会触发IDEA重新编译,IDEA变得很卡,开发体验不好。

其实IDEA提供了对spring-boot-devtools的相应支持的,打开IDEA——Help在弹出网页中输入spring boot,就能找到Configure application update policies with devtools这篇文档。

实际操作:

1.在你的spring boot项目中引入依赖spring-boot-devtools
2.找到main方法,运行一下项目。注意一定要通过点击main方法运行,而不能是通过mvn spring-boot:rungradle bootRun,如下图:

《Intellij IDEA下Spring Boot热切换配置》

《Intellij IDEA下Spring Boot热切换配置》

3.运行后我们就可以打开Run——Edit Configurations,在SpringBoot下设置On Update actionUpdate classes and resources,如下图:

《Intellij IDEA下Spring Boot热切换配置》

4.设置后,通过main方法运行,或者在菜单栏点击Run图标运行,如图:

《Intellij IDEA下Spring Boot热切换配置》

5.当我们修改完代码后,IDEA不会自动编译重新启动SpringBoot,而是我们需要按一下左下角的Run栏目中的Update xxx application才会触发热切换。当然我们也可以用快捷键ctrl+F10。如下图:

《Intellij IDEA下Spring Boot热切换配置》

    原文作者:煲煲菜
    原文地址: https://segmentfault.com/a/1190000015930347
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞