I\'m new to Spring Boot and my problem is that I have Spring Boot project and I am intending to view my HTML pages with Thymeleaf but Spring can\'t resolve my JavaScript and CSS
You should use relative path to your JavaScript and CSS files:
<link href="../../static/css/style.css" rel="stylesheet" type="text/css" media="screen"/>
or you can use th:href
Thymeleaf's tag as well:
<link th:href="@{css/style.css}" href="../../static/css/style.css"
rel="stylesheet" type="text/css" media="screen"/>
I have found that Spring automatically searches for: /resources/
.
So what I did was removed all the pre-directories by using find all.
So, in my case what used to be for example: /static/css/style.css
& /templates/index.html
became: /css/style.css
& /index.html
Now the question remains how does Spring boot know what folder to look in without you defining it: Spring looks at the extension. When spring boot sees .html
, it looks for it in a folder called /templates
.