用Intellij進(jìn)行開發(fā)時(shí),直接啟動(dòng)Spring的Application,然后修改代碼,可以自動(dòng)重啟,不需要停下來、打包、運(yùn)行。
- 在 pom.xml 里增加一個(gè)依賴:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
<scope>runtime</scope>
</dependency>
- 在 pom.xml 里添加 spring-boot-maven-plugin:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!--fork : 如果沒有該項(xiàng)配置,可能devtools不會(huì)起作用,即應(yīng)用不會(huì)restart 這個(gè)要手動(dòng)加進(jìn)去 -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
注:得加 <fork>true</fork> 。
-
在 Intellij 里設(shè)置自動(dòng)編譯、打包
image.png
- 允許編譯器在app允許時(shí)自動(dòng)編譯
快捷鍵Cmd + Alt + Shift + /,選擇Registry,然后勾選compiler.automake.allow.when.app.running:
image.png
參考文檔
https://blog.csdn.net/qq_27886997/article/details/82799217
這篇還介紹了devtools的原理、排除資源、禁用重啟等等,還是挺有用的。

