使用 Spring MVC 和 Boot 刷新静态内容 [英] Refreshing static content with Spring MVC and Boot

查看:31
本文介绍了使用 Spring MVC 和 Boot 刷新静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在评估 Spring MVC &用于构建 Web 应用程序的 Boot 和 AngularJs.我遇到了一个问题,当我对我的静态内容(html、js、css)进行修改时,我每次都必须重新启动应用程序.我希望有某种方法可以解决这个问题,因为为静态内容更改重新启动整个应用程序效率不高.我尝试过的所有其他 Web 应用程序框架都允许动态更新静态内容文件(即使只是 Spring MVC 和普通的旧 WAR 应用程序).

I'm evaluating Spring MVC & Boot and AngularJs for building web applications. I've run into the problem that when I make modifications to my static content (html, js, css), I have to restart the application every time. I hope there is a some way of solving that because restarting the whole application for static content changes is not efficient. Every other web app framework I've tried allows updating static content files on the fly(even just Spring MVC and plain old WAR application).

我已经从使用 Spring Boot Actuator 构建 RESTful Web 服务"指南 (http://spring.io/guides/gs/actuator-service/).基本上它使用 Spring Boot 和 MVC 控制器来创建 REST 服务.此外,我使用了使用 AngularJS 使用 RESTful Web 服务"指南(http://spring.io/guides/gs/sumption-rest-angularjs/) 使用 AngularJS 构建前端.它创建一个网页,显示来自 REST 服务的响应.我所做的唯一更改是向我的应用程序发出请求,而不是http://rest-service.guides.spring.io/greeting".我的静态内容存储在src/main/resources/public"文件夹中.除了不重新加载静态内容外,此设置可以正常工作.

I've setup my project from "Building a RESTful Web Service with Spring Boot Actuator" guide (http://spring.io/guides/gs/actuator-service/). Basically it uses Spring Boot and MVC controllers to create a REST service. In addition, I've used "Consuming a RESTful Web Service with AngularJS" guide (http://spring.io/guides/gs/consuming-rest-angularjs/) to build a frontend with AngularJS. It creates a web page that displays the response from the REST service. The only change I've made is that the requests are made to my application instead of "http://rest-service.guides.spring.io/greeting". My static content is stored in "src/main/resources/public" folder. This setup works correctly except it doesn't reload static content.

推荐答案

文档说所有现代 IDE 都允许重新加载静态资源,通常还允许热交换 Java 类更改"(https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/howto.html#howto-hotswapping).这是真的.Eclipse 默认情况下或多或少会这样做,我不是 IntelliJ 用户,但据我所知,您也可以将其配置为自动构建.

The docs say "all modern IDEs allow reloading of static resources and usually also hot-swapping of Java class changes" (https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/howto.html#howto-hotswapping). It's true. Eclipse does it more or less by default, and I'm not an IntelliJ user, but from what I understand you can configure it to build automatically as well.

这篇关于使用 Spring MVC 和 Boot 刷新静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆