Adding Static Content To Spring Boot MVC

As I learn new frameworks, I often get a good idea stuck in my head that I really want to implement. Often, the idea is overly ambitious for my knowledge of the tool, but sometimes it hits the sweet spot between “That should be pretty easy to implement” and “I really don’t want to dig into the documentation to figure this out”.

Using a tool that is rather young, like Spring Boot, makes me dread the learning process even more as they often don’t have the documentation I need in place, so instead I need to dig through source code and examples that look related.

My plan was to add static content to a Spring Boot web site. I’ve seen the dynamic content via Spring @Controllers, but I still need to add images and CSS if I want a decent site.

So, my journey began at Spring Boot’s GitHub repo, which has a large number of undocumented examples. My answer, of course, lay beneath the folders of the well named spring-boot-sample-web-static example, and like all other Spring Boot defaults, it was an obvious solution.

Add the static files to src/main/webapp. Where else would you put it?

My own example is now on GitHub which combines the Ember.js template project to the Spring Boot REST Template project.

The last step we need to create a fully functional application is to modify the Ember.js template to pull data from the REST services.

Jay Lindquist avatar
About Jay Lindquist
Developer and wonderer