I can't figure out why spring boot can't load stylesheets and images files. My project structure looks like this:

enter image description here

Thymeleaf code snippet responsible for linking css:

<link href="../static/css/styles.css" rel="stylesheet" type="text/css">

ViewResolver class configuration:

  @Configuration
public class ViewResolverConfiguration implements WebMvcConfigurer {

  @Bean
  public ViewResolver viewResolver(){

    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/");
    resolver.setSuffix(".html");
    return resolver;
  }

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**")
            .addResourceLocations("/resources/");
  }

  @Override
  public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
    configurer.enable();
  }
}

Message from the browser console

enter image description here

0 Answers