Home > Enterprise >  How to add css to a Spring Boot project?
How to add css to a Spring Boot project?

Time:07-04

When I include css it throws an error o.s.web.servlet.PageNotFound: No match for GET /css/s.css In spring sequiriti I have added

  .antMatchers("/css/**").permitAll()

Link in html:

  <link rel="stylesheet" type="text/css" th:href="@{/css/s.css}">

architecture folders:

  -Resources
    -static
       -css
          -s.css
     -templates
       -main
          -home.html

CodePudding user response:

Try to add such thing

public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
      
        registry
            .addResourceHandler("/css/**")
            .addResourceLocations("classpath:/static/css/");
    }
}

CodePudding user response:

public class WebConfig implements WebMvcConfigurer {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
  
    registry
        .addResourceHandler("/css/**")
        .addResourceLocations("classpath:/static/css/");
}

}

  • Related