Shortly I have application which is structered as below and the problem is that spring boot not scanning static folder recursively. I mean
if i put bootstrap.min.css to static/css/bootstrap.min.css
it is okay no problem but if i put into another folder in subpackage of static folder static/bootstrap/bootstrap.min.css
, just like in the screenshot then I am not able load these resources. How can I handle this ? Thanks in advance.
Asked
Active
Viewed 537 times
0

Mesut Dogan
- 572
- 7
- 16
-
http://stackoverflow.com/questions/1483063/how-to-handle-static-content-in-spring-mvc -this may help – Valath Jan 27 '17 at 01:29
1 Answers
2
Your URL lacks a leading slash.
http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#link-urls
There are different types of URLs:
- Absolute URLs: http://www.thymeleaf.org
- Relative URLs, which can be:
- Page-relative: user/login.html
- Context-relative: /itemdetails?id=3 (context name in server will be added automatically)
- Server-relative: ~/billing/processInvoice (allows calling URLs in another context (= application) in the same server.
- Protocol-relative URLs: //code.jquery.com/jquery-2.0.3.min.js
The URL in your screenshot, bootstrap/css/bootstrap.min.css, is page-relative.
What you want is a context-relative URL. When your file is in src/main/resources/static/css/bootstrap.min.css, use:
th:href="@{/css/bootstrap.min.css}"
When it's in in src/main/resources/static/bootstrap/bootstrap.min.css, use:
th:href="@{/bootstrap/bootstrap.min.css}"
Furthermore, instead of manually downloading bootstrap.min.css, I suggest you use the Bootstrap WebJar and then use the following href:
th:href="@{/webjars/bootstrap/3.3.6/css/bootstrap.min.css}"

Marc Tarin
- 3,109
- 17
- 49