日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

springboot-devtools idea或eclipse 热加载

發布時間:2023/12/10 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot-devtools idea或eclipse 热加载 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

大家好,我是烤鴨:

? ? 今天分享一下springboot項目的熱加載。

? ? 第二種方式在eclipse和idea中都可以。雖然會有一些小坑。

方式有兩種:

1.? ?springloaded(無效)

<!-- https://mvnrepository.com/artifact/org.springframework/springloaded --> <dependency><groupId>org.springframework</groupId><artifactId>springloaded</artifactId><version>1.2.8.RELEASE</version><scope>provided</scope> </dependency>

2.? ?springboot-devtools(推薦)

? ? 首先看一下官網,簡單通俗。

????https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html

? ? 2.1????pom文件

<!-- 熱加載 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><version>2.0.0.RELEASE</version><optional>true</optional><scope>true</scope></dependency><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><!-- fork: 如果沒有配置該項配置,devtools不會起作用的,即應用不會restear --><fork>ture</fork></configuration></plugin></plugins>

????2.2????異常情況說明

? ? ????2.2.1????類型轉換異常:

????????https://blog.csdn.net/m0_38043362/article/details/78064539

????? ? 官網的解決方式:

????????

????? ? 按這個思路,首先在src/main/resources 目錄下建立META-INF文件夾,創建spring-devtools.properties

????? ? 內容:

restart.include.mapper=/mapper-[\\w-\\.]+jar restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar

最開始給我報的是類型轉換異常,因為用的是shiro,所以我在properties中加入了shiro的包:

restart.include.shiro=/shiro-[\\w-\\.]+jar

后來又報thymeleaf的異常,導致項目無法啟動,加入了thymeleaf的包

restart.include.thymeleaf=/thymeleaf-[\\w-\\.]+jar

再后來...

總之是哪個包報錯了,就把響應的pom文件中引的這個包,在這個properties中配置一下。

最后:

spring-devtools.properties :

restart.include.mapper=/mapper-[\\w-\\.]+jar restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar # 因為我項目中引用了 org.crazycake:shiro-redis ,所以要引用下面這個配置 restart.include.shiro=/shiro-[\\w-\\.]+jar restart.include.thymeleaf=/thymeleaf-[\\w-\\.]+jar restart.include.spring=/spring-[\\w-\\.]+jar restart.include.mybatis=/mybatis-[\\w-\\.]+jar restart.include.springframework=/org.springframework-[\\w-\\.]+jar restart.include.springfox=/springfox-[\\w-\\.]+jar

? ? 2.2.2? ? 小結

? ? 官網的意思是任何jar包都可以被"基本的"類加載器加載。如果你的項目是多模塊的,不是每個模塊都可以導入到你的IDE中。

? ? 所以需要自定義。重點是這兩句。

????The?include?elements are items that should be pulled up into the “restart” classloader, and the?exclude?elements are items that should be pushed down into the “base” classloader.

? ? ????include的包含的jar包被放入了“重啟”的類加載器,而exclude的包含的jar包被推入了“基本”類加載器。

All property keys must be unique.? ? 定義的Key值必須唯一。

? ?????? ?我個人的理解就是需要被他的類加載器加載的就不定義,如果有自己的類需要自己的類加載器,比如shiro等等,就需要定義在這個propertiesdevtools負責的是對基本類加載器中的類的加載。

3.? ? IDE中使用

? ? 3.1? ? eclipse

????

????? ? 打開自動編譯以后,每次編譯時間長短不一樣。多修改保存幾次就好了。如果還不行,就取消自動編譯再打鉤

? ? 3.2? ? idea

File——>settings——>Compiler——>Build project automatically

? ??? ?

快捷鍵:CTRl+ALT+SHIFT+/? ? ——>? Registry


如果這些還是無效的話,可以試試手動編譯。右鍵如下圖。快捷鍵Ctrl+Shift+F9


4.? ? 特別說明

? ? ?之前出現過:

? ? ?1.????eclipse需要多次保存class文件才能生效。

? ? ?2.????在idea上出現必須手動編譯才能生效。

? ? ?3.? ? 靜態資源(js.css)或者模板文件(ftl,thymeleaf)沒有reload。

? ? ?原因猜想:

????? ? 之前安裝過JRebel(熱加載插件,需要收費),雖然卸載了,不知道有沒有影響。

????? ? 電腦的原因,換一臺性能好點的電腦,上述問題就沒有了。

????? ? 有類似問題的,歡迎交流。

?????

總結

以上是生活随笔為你收集整理的springboot-devtools idea或eclipse 热加载的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。