我不知道为什么Spring Boot无法加载样式表和图像文件。 我的项目结构如下:
负责链接CSS的Thymeleaf代码段:
<link href="../static/css/styles.css" rel="stylesheet" type="text/css">
ViewResolver类配置:
@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();
}
}
来自浏览器控制台的消息