skip to Main Content

The problem is that a thymeleaf does not find my css file

Project structure
enter image description here

I am able to access css file with given url http://localhost:8080/styles.css

I use spring boot 3.1.1

I have tried

and

as well as

Template does show correctly but css is not applied

2

Answers


  1. This is the correct syntax in your case:

    <link th:href="@{/styles.css}" rel="stylesheet" />
    
    Login or Signup to reply.
  2. i see you found the solution
    I will give some details as i found.

    When using thymeleaf, springboot, spring security
    thymeleaf cannot access css files because of spring security

    `@Bean
    public WebSecurityCustomizer webSecurityCustomizer() {
        return (web) -> web.ignoring().requestMatchers("/css/**", "/js/**");
    }`
    

    Will solve the problem. It’s work for me.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search