Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refreshing static content with Spring MVC and Boot

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).

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.

like image 453
palto Avatar asked Jul 15 '14 15:07

palto


People also ask

How does Spring Boot serve static content?

Using Spring Boot Spring Boot comes with a pre-configured implementation of ResourceHttpRequestHandler to facilitate serving static resources. By default, this handler serves static content from any of the /static, /public, /resources, and /META-INF/resources directories that are on the classpath.

How reload properties file without restarting server in spring boot?

include=refresh: this is actuator property which will help us to refresh the properties without restarting the server.


1 Answers

A recap of the original problem

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 had the same problem and finally solved it by adding

<configuration>     <addResources>true</addResources> </configuration> 

to spring-boot-maven-plugin in the pom.xml I got confused by this spring-boot-devtools thing, but it had no effect whatever I did.

My static content is stored in "src/main/resources/public" folder.

Your path is just fine. src/main/resources/static is also fine.

like image 110
eigil Avatar answered Sep 22 '22 03:09

eigil