简体   繁体   中英

How to add css to a Spring Boot project?

When I include css it throws an error osweb.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

Try to add such thing

public class WebConfig implements WebMvcConfigurer {

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM