liveBook · Manning

Static resource directory

As explained in Spring in Action, Sixth Edition

A static resource directory is a web application's directory for files such as images, stylesheets, and JavaScript that are served without template rendering.

A static resource directory stores files that the browser receives without template rendering, including images, stylesheets, and JavaScript. section 1.2.2

Serving a Taco Cloud logo

Place the image at /src/main/resources/static/images/TacoCloud.png. A Thymeleaf template can then reference it with th:src="@{/images/TacoCloud.png}", using a context-relative URL. section 1.3.2

Use the directory for browser-facing assets while keeping rendered pages in the templates directory.

  • Add images, stylesheets, or JavaScript beneath src/main/resources/static. section 1.2.2
  • Reference an asset from a view with its context-relative path, such as /images/TacoCloud.png. section 1.3.2
Figure 1.6 The initial Spring project structure as shown in Spring Tool Suite

Use the project-structure figure to locate the static directory alongside templates and application code. section 1.2.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines the directory’s purpose and demonstrates asset placement and referencing, without detailing static-resource resolution internals.
Examples
Uses a Taco Cloud logo stored under static/images and referenced from a Thymeleaf home-page template.
What it assumes
Assumes a Spring project structure and introduces the distinction between static content and rendered templates.
What you can do after
Apply it via Spring Boot by placing browser assets under static and referencing them with context-relative URLs.
How it connects
Connects static resources with Spring Boot project structure, templates, Thymeleaf, and context-relative paths.

Also explained in

Compare how 2 books explain static resource directory →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.