熱部署
Spring Boot 支援熱部署。本節回答了有關其工作原理的問題。
重新載入靜態內容
有幾種熱過載選項。推薦的方法是使用 [`spring-boot-devtools`](../reference/using/devtools.html),因為它提供了額外的開發時特性,例如對快速應用程式重啟和 LiveReload 的支援,以及合理的開發時配置(如模板快取)。Devtools 透過監控類路徑中的更改來工作。這意味著靜態資源更改必須經過“構建”才能生效。預設情況下,在 Eclipse 中儲存更改時會自動發生這種情況。在 IntelliJ IDEA 中,Make Project 命令會觸發必要的構建。由於[預設的重啟排除項](../reference/using/devtools.html#using.devtools.restart.excluding-resources),對靜態資源的更改不會觸發應用程式的重啟。然而,它們會觸發即時過載。
或者,在 IDE 中執行(尤其是在開啟除錯的情況下)是進行開發的良好方式(所有現代 IDE 都允許重新載入靜態資源,並且通常也允許熱替換 Java 類更改)。
最後,可以配置 [Maven 和 Gradle 外掛](../build-tool-plugin/index.html)(請參閱 addResources
屬性)以支援從命令列執行,直接從原始檔重新載入靜態檔案。如果你使用更高階的工具編寫程式碼,可以將其與外部 css/js 編譯器程序一起使用。
無需重啟容器即可重新載入模板
Spring Boot 支援的大多數模板技術都包含一個用於停用快取的配置選項(本文件後面會介紹)。如果你使用 spring-boot-devtools
模組,這些屬性會在開發時為你[自動配置](../reference/using/devtools.html#using.devtools.property-defaults)。
Thymeleaf 模板
如果你使用 Thymeleaf,將 spring.thymeleaf.cache
設定為 false
。有關其他 Thymeleaf 自定義選項,請參閱 [`ThymeleafAutoConfiguration`](https://github.com/spring-projects/spring-boot/tree/v3.4.5/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java)。
FreeMarker 模板
如果你使用 FreeMarker,將 spring.freemarker.cache
設定為 false
。有關其他 FreeMarker 自定義選項,請參閱 [`FreeMarkerAutoConfiguration`](https://github.com/spring-projects/spring-boot/tree/v3.4.5/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfiguration.java)。
FreeMarker 的模板快取不支援 WebFlux。 |
Groovy 模板
如果你使用 Groovy 模板,將 spring.groovy.template.cache
設定為 false
。有關其他 Groovy 自定義選項,請參閱 [`GroovyTemplateAutoConfiguration`](https://github.com/spring-projects/spring-boot/tree/v3.4.5/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfiguration.java)。