Skip to content

SpringBoot with Thymeleaf – css not found

First to say is that I’ve been searching for a solution for a while now and I’m quite desperate now.

I cannot get the css file to be accessible from html page when run by Spring Boot.


<html xmlns=""
    <head lang="en">
        <title th:text='#{Title}'>AntiIntruder</title>
        <meta charset="UTF-8" />
        <link rel="stylesheet" type="text/css" media="all" href="../assets/css/style.css" th:href="@{/css/style.css}" />

@SpringBootApplication // adds @Configuration, @EnableAutoConfiguration, @ComponentScan
public class Application extends WebMvcConfigurerAdapter {

    public static void main(String[] args) {, args);

    public void addResourceHandlers(ResourceHandlerRegistry registry) {

folder structure:

folder structure

I’ve tried putting the css folder into a static folder and/or removing the addResourcesHandlers, referencing to the css by relative path and some other things. Nothing seems to resolve this. Please, let me know also if you tried to solve this but did not find a solution, so that I know, that I’m not ignored.


The problem was the @EnableWebMvc annotation in the file. As soon as I removed that one, the css started to be available at localhost:8080/css/style.css but was not applied. So far I haven’t found the reason why the @EnableWebMvc was causing the problem.

Then I removed a controller mapped to /** that I had implemented in order to display custom error page.

public String notFound() {
    return "errors/404";

After removing also this one, I’ve got my css working. =)