解決idea debug模式下修改代碼卻不能生效


IDEA環境下使用devtools實現熱加載與熱部署實現修改代碼不需重啟

1.引入devtools的maven依賴

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-devtools</artifactId>
	<optional>true</optional>
</dependency>

2.在 plugin 中配置另外一個屬性 fork,並且配置為 true。

<build>
	<plugins>
   	 	<plugin>
        	<groupId>org.springframework.boot</groupId>
        	<artifactId>spring-boot-maven-plugin</artifactId>
        	<configuration>
            	<fork>true</fork>
        	</configuration>
    	</plugin>
	</plugins>
</build>

3.設置IDEA

運行時編譯配置:組合鍵:“Shift+Ctrl+Alt+/” ,選擇 “Registry” ,選中打勾 “compiler.automake.allow.when.app.running” 。

4.自動化編譯配置:

“File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,選中打勾 “Build project automatically” 。

5. 進行一下application.properties配置

在有些版本我們需要配置熱加載生效的開關,使其值等於true。下文是properties格式配置,喜歡yml格式的同學可以自行調整一下


#熱加載生效
spring.devtools.restart.enabled=true
#額外新增的熱加載目錄
spring.devtools.restart.additional-paths= src/main/java
#熱加載排除目錄
#spring.devtools.restart.exclude= 

參考

手把手教你學Spring Boot 2.X


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM