重新加载静态内容spring boot应用程序

时间:2017-04-29 08:17:44

标签: spring spring-boot static gulp browser-sync

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

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

3 个答案:

答案 0 :(得分:6)

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

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

“file:”导致在刷新浏览器时重新加载内容, see related issue

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

另请参阅documentationtutorial

答案 1 :(得分:0)

通常,spring-boot插件会将静态内容复制到构建目录(如果使用maven,则为目标)。您可以在{build-directory} / classes / static中找到您的文件:这些文件应该修改以反映更改。您还应该将更改复制到resources / static,因为无论何时重新启动spring boot,都会复制文件。

答案 2 :(得分:0)

如果使用 application.yml 文件进行配置,插入:

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