I have been searching all day, moved the style.css everywhere and still not managed to get it loaded. The images wont load as well.
My structure:

But if i click the firefox button, it loads:

This is how the style.css is imported in the head of the index:

(tried all kind of combinations)
When i check the developer tools, it says 404 for GET request (style.css and the pictures)
Spring Boot knows where the static directory is, so you don't need to use the ../ technique to get to the files within. The other part is that you should be using an annotation to get there. It may depend on what view template you are using, but for thymeleaf this is how you would achieve pulling in the css file:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Your Title</title>
<link rel="stylesheet" th:href="@{/css/style.css}" />
</head>
Notice the annotation in th:href="@{/css/style.css}"
Make sure you include the namespace of your view template, th in the example.
Images work the same way:
<img th:src="@{/img/stanev2.png}" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With