好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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:run 或 gradle bootrun ,如下图:

3.运行后我们就可以打开 run —— edit configurations ,在 springboot 下设置 on update action 为 update classes and resources ,如下图:

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

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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

原文链接:https://segmentfault.com/a/1190000015930347

查看更多关于Intellij IDEA下Spring Boot热切换配置的详细内容...

  阅读:48次