![](/img/trans.png)
[英]Spring Boot maven project from Eclipse doesn't work in Intellij
[英]Spring Boot Developer Tools Auto restart doesn't work in IntelliJ
最近在 IntelliJ 中使用 spring-boot-devtools 啟動了 spring-boot,並花了幾個小時試圖弄清楚為什么 IntelliJ 不會接受我的更改並自動重啟嵌入式 tomcat。
此鏈接中的信息也沒有幫助: https : //dzone.com/articles/spring-boot-application-live-reload-hot-swap-with
為了使其工作,您需要:
1) 在 maven 或 gradle 中啟用 devtools。 在Maven中它看起來像:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope><!-- -->
<optional>true</optional>
</dependency>
2)在IntellijIDEA中:進入設置(ctrl +alt+s)->構建、執行、部署->編譯器,勾選“自動構建項目”
3)在 IntellijIDEA 中:按 ctrl+shift+a,然后輸入“registry”並單擊它。 然后啟用選項“compiler.automake.allow.when.app.running”。
4)重新啟動intellijIDEA! 因為這個,我失去了幾個小時:/
它現在應該可以工作了。
請注意:
- 您不需要附加路徑或觸發器文件即可按預期工作。
- 如果您使用 maven 啟動參數-Dspring-boot.run.fork=false
來啟用調試,則 devtools 被禁用,因此不應在代碼更改時重新啟動。
- 在 yaml 文件中,您需要對來自 pom.xml 的參數使用引號。 如果不這樣做,該項目將第一次運行,然后在重新啟動時失敗。
spring:
profiles:
active: '@spring.profiles.active@'
它適用於 INTELLIJIDEA 社區版,值得大寫,因為許多答案說它只適用於終極...
通過將項目名稱從 spring-boot 更改為 spring-boot-xxx(基本上除了 spring-boot 之外的任何內容)解決了該問題。
如果您仔細閱讀文檔,這里提到的是:
在決定類路徑上的條目是否應在更改時觸發重新啟動時,DevTools 會自動忽略名為spring-boot 、spring-boot-devtools、spring-boot-autoconfigure、spring-boot-actuator 和 spring-boot-starter 的項目。
使用 Ctrl+F9 構建項目會自動觸發重新啟動。 如果您希望在保存類文件后立即自動觸發,您可以按照問題中提供的熱插拔鏈接進行操作。
Spring Boot 還具有在特定文件更改時觸發重啟的選項,並且可以使用以下屬性在 application.properties 中進行配置
spring.devtools.restart.trigger-file=
希望這可以幫助某人節省時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.