Refreshing static content with Spring MVC and Boot

前端 未结 15 2144
迷失自我
迷失自我 2020-11-28 07:02

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,

15条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 07:25

    You have two possebilities how to serve static webcontent

    1. From the classpath (per default src/main/resources/static or src/main/resources/public or META-INF/resources/)
    2. From the file system (per default src/main/webapp)

    If you pick solution 1) - you can safely copy the jar around as the static web content is within that jar. If you want that the server picks up changes, you need to do (auto)hotswapping.

    If you pick solution 2) - everything will work out of the box, every change will be automatically picked up. HOWEVER - if you copy the final jar to a different location - things will stop working. That is unless you specify an absolute path in application.properties. For example:

    spring.resources.static-locations=file:///C:/myspringbootapp/src/main/webapp
    

    So solution 2) is easier but less portable. Solution 1) is portable but more difficult to use(ide config).

提交回复
热议问题