重新加载静态内容 Spring Boot 应用程序 [英] Reload static content spring boot application

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

问题描述

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

I am using Netbeans and I am developing my first web application using spring boot. I was keeping my HTML, js, CSS in "webapp" folder and then I refactored my project and I put all static content in /resources/static. Since then, I have to rebuild my project every time because the static content isn't reloaded.

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

Can I easily bypass this problem if I'll use browser-sync plugin for Gulp?

推荐答案

在 src/main/resources/application.properties 中添加以下内容:

Add the following to src/main/resources/application.properties:

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

文件:"导致刷新浏览器时重新加载内容,查看相关问题.

The "file:" causes the content to be reloaded on refreshing the browser, see related issue.

或者,文件 资源位置 可以是 在运行时发现以编程方式添加.

Alternatively, the file resource locations can be discovered at runtime and added programmatically.

另见 文档教程.

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

Note that prior to Spring Boot 2.4, the property was called "spring.resources.static-locations".

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

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