![](/img/trans.png)
[英]Spring Boot - Update ResourceHandlerRegistry without restarting app
[英]Spring Boot, update frontend without restarting the application
在 Spring Boot 中使前端部分更新而不重新啟動應用程序?
我為靜態網頁和 css 找到的最佳解決方案是https://stackoverflow.com/a/39334398/6467734並且在不重新啟動服務器的情況下加載代碼(包括 jsp),您可以使用 Spring Boot Devtools 依賴項
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
我是 Eclipse 用戶(通過 Spring Tool Suite),如果應用程序在調試模式下運行,我在重新加載靜態內容方面從來沒有任何問題。 只需右鍵單擊主類和“Debug As->Java App”(或“Spring Boot App”,都是一樣的)。 您還必須確保將工作區配置為“自動構建”,但據我所知,這是默認設置。
我無法為其他 IDE 的用戶提供如此具體的建議,但我確信他們都具有相同的功能。
在 Intellij IDEA 中以Debug模式運行您的項目,您將獲得相同的效果。
或者外部化您的 static 。
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
private String extStaticPath = "/var/www/site1/";
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**")
.addResourceLocations(extStaticPath)
.setCachePeriod(0);
}
}
對於 JSP 文件嘗試設置server.jsp-servlet.init-parameters.development=true
將以下內容添加到 src/main/resources/application.properties:
spring.resources.static-locations[0]=file:src/main/resources/static/
spring.resources.static-locations[1]=classpath:/static/
“文件:”導致在刷新瀏覽器時重新加載內容
或者,可以在運行時發現文件資源位置並以編程方式添加。 我希望這有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.