springboot整合mybatis增刪改查(二):springboot熱部署

SpringBoot整合熱部署

傳統(tǒng)情況下, 我們用idea運(yùn)行springboot程序時(shí), 如果我們需要修改類里的方法,或者其他信息
我們需要修改完保存,并且重啟springboot,有時(shí)候會(huì)很浪費(fèi)時(shí)間。

熱部署的原理是使用了兩個(gè)ClassLoader,一個(gè)Classloader加載那些不會(huì)改變的類(第三方Jar包),另一個(gè)ClassLoader加載會(huì)更改的類,稱為restart ClassLoader,這樣在有代碼更改的時(shí)候,原來(lái)的restart ClassLoader 被丟棄,重新創(chuàng)建一個(gè)restart ClassLoader,由于需要加載的類相比較少,所以實(shí)現(xiàn)了較快的重啟時(shí)間

pom.xml中添加devtools依賴

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 這個(gè)需要為 true 熱部署才有效 -->
        </dependency>

配置 application.properties

spring.devtools.remote.restart.enabled=true
spring.devtools.restart.additional-paths=springboot-mybatis/src/main

注意

默認(rèn)情況下,/META-INF/maven,/META-INF/resources,/resources,/static,/templates,/public這些文件夾下的文件修改不會(huì)使應(yīng)用重啟,但是會(huì)重新加載(devtools內(nèi)嵌了一個(gè)LiveReload server,當(dāng)資源發(fā)生改變時(shí),瀏覽器刷新)。

IDEA配置

當(dāng)我們修改了Java類后,IDEA默認(rèn)是不自動(dòng)編譯的,而spring-boot-devtools又是監(jiān)測(cè)classpath下的文件發(fā)生變化才會(huì)重啟應(yīng)用,所以需要設(shè)置IDEA的自動(dòng)編譯:
(1)File-Settings-Compiler-Build Project automatically
(2)ctrl + shift + alt + /,選擇Registry,勾上 Compiler autoMake allow when app running

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容