spring - 重新加载静态内容 Spring Boot 应用程序

标签 spring spring-boot static gulp browser-sync

我正在使用 Netbeans,并且正在使用 Spring Boot 开发我的第一个 Web 应用程序。我将 HTML、js、CSS 保存在“webapp”文件夹中,然后重构了我的项目,并将所有静态内容放入 /resources/static 中。从那时起,我每次都必须重建我的项目,因为静态内容没有重新加载。

如果我为 Gulp 使用浏览器同步插件,我可以轻松绕过这个问题吗?

最佳答案

将以下内容添加到 src/main/resources/application.properties:

spring.web.resources.static-locations[0]=file:src/main/resources/static/
spring.web.resources.static-locations[1]=classpath:/static/

“文件:”会导致刷新浏览器时重新加载内容, see related issue .

或者,文件 resource locations可以是discovered在运行时和added programmatically .

另请参阅documentationtutorial .

请注意,在 Spring Boot 2.4 之前,该属性称为“spring.resources.static-locations”。

关于spring - 重新加载静态内容 Spring Boot 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43693393/

相关文章:

java - Gradle 编译项目因 Spring Boot 插件失败

java - 静态访问 HashMap/Array?

c - 静态变量的地址是否可以被其他文件访问

java - 不访问日期选择器会出现转换错误

java - 从数据库获取 hibernate 中的 List<String>

java - Spring Boot CRUD 应用程序 - Bean 未找到错误

java - 面向对象设计和在抽象父类(super class)中初始化静态成员

spring - 在具有共享服务的单个应用程序中使用 Apache cxf 和 spring mvc

java - 你能告诉我,我的请求映射有什么问题吗?

java - Spring Rest Template Http客户端错误异常