天天看点

在SpringBoot中使用热部署(DevTools)

一、简介

  有时候我们开发完SpringBoot项目后,启动运行。但是经常发现代码需要反复修改,然后修改部分内容后需要再启动....这样太费时了,热部署就是用来解决这一问题。让你修改完代码后,能自动执行编译并运行。

二、工具

  IntelliJ IDEA、SpringBoot 2.0.4

三、步骤

  1、创建正常SpringBoot的Maven项目

  2、在需要热部署的项目中(或者在全局父Maven模块中)加入DevTools

  

<dependencies>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <version>2.0.4.RELEASE</version>
        </dependency>

    </dependencies>      
在SpringBoot中使用热部署(DevTools)

  3、依次点开菜单 【File】-【Settings】-【Build,Execution,Deployment】-【Compiler】-勾选右侧的【Build project automatically】

在SpringBoot中使用热部署(DevTools)

  4、按下Ctrl+Shift+A,打开搜索,输入registry,并打开搜索到的该项设置。

在SpringBoot中使用热部署(DevTools)

  5、找到compiler.automake.allow.when.app.running项,并打勾。

在SpringBoot中使用热部署(DevTools)

  6、最重要的一步:重启IEDA。

宋兴柱(Sindrol):转载内容,请标明出处,谢谢!源文来自 宝贝云知识分享:https://www.dearcloud.cn