天天看點

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

今天給springboot項目引入了 mybatis-plus ,之前是JPA,

到寫sql改變時 rebuild項目 sql不生效 就是idea沒法熱部署xml檔案,這樣sql每改變一次等重新開機項目 非常麻煩,上csdn搜尋文章,裝上了Jrebel,且配置好了,依舊用不了.

受這篇部落格啟發,

mybatis-plus 版本3.3.2 要下載下傳 jrebel-mybatisplus,

最終sql改變,無需重新開機項目就生效。

IDEA下載下傳Jrebel插件并激活

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署
IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

激活位址為:http://jrebel.qekang.com/GUID

GUID生成位址:https://www.guidgen.com/

然後随便填寫一個自己的郵箱

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署
IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

下圖表示激活成功

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

選擇需要進行熱部署的項目

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

以jrebel方式啟動,如下圖所示表示配置成功

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

修改代碼之後會出現如下圖所示,并不用手動重新開機

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

以上就是jrebel熱部署配置,修改代碼熱部署步驟配置已經完成

Mybatis-plus配置

首先官網:https://mp.baomidou.com/guide/hot-loading.html 已經明确表示 3.0.6版本上移除了該功能,不過最新快照版已加回來并打上廢棄辨別,3.1.0版本上已完全移除,如下圖所示 本人接下來使用3.1.0版本進行配置,這裡為什麼不使用3.1.0以後版本呢,稍候就我自己的原因解釋一下,各位個自行選擇 3.1.0之後的版本

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

因為是springboot項目,是以選擇mybatis-plus-boot-starter

<!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-boot-starter -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.1.0</version>
        </dependency>

           
IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

在gitHub上下載下傳jrebel-mybatisplus插件到本地用idea打開并執行mvn clean package進行打包,如下圖所示

插件源碼位址:https://github.com/SweetInk/jrebel-mybatisplus

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

如上圖所示打包完成之後target檔案夾會出現一個jar包,将這個包複制出來放在任意檔案夾下 比如:D:\jr-mybatisplus-1.0.2.jar

然後進入idea的安裝檔案夾下面的bin目錄,比如:C:\Users\Administrator\Desktop\IntelliJ IDEA 2019.3\bin 找到以下檔案,打開并加上:-Drebel.plugins=D:\jr-mybatisplus-1.0.2.jar 如下圖所示

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署
IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

也可以直接在idea中設定VM參數,如下圖所示,這樣做的話那就每個項目都要配置,是以不建議在IDEA中配置

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

配置好之後,啟動項目看效果,如下圖所示

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

上圖是沒有加參數的查詢,可以看到控制台打出的是:select * from lc_user 下圖我加了條件,并沒有重新開機,再次調用的時候打出了:Reloading SQL maps 表示重新加載了SQL映射,并且下面的SQL語句也加了條件,可以看到熱部署是生效的。

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

至于上面說到為什麼用3.1.0版本呢,那是因為3.2版本棄用了性能分析攔截器,也就是說使用3.2版本控制台将不會打出 每條 SQL 語句及其執行時間(下圖所示)

IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署
IDEA配置springboot項目使用Jrebel+Mybatis-plus進行熱部署

以上就是所有springboot+jrebel+mybatis-plus進行熱部署的配置,已經配置成功。

繼續閱讀