首页 > 编程语言 > 详细

springboot+thymeleaf不能读取静态资源的问题

时间:2021-04-13 23:42:16      阅读:22      评论:0      收藏:0      [点我收藏+]

最近用springboot+thymeleaf的时候又发现在运行的时候,静态资源无法展示,网上搜了好多方法:

方法一:

在application.properties文件中添加 spring.mvc.static-path-pattern=/static/**

技术分享图片

spring.mvc.static-path-pattern=/static/**

方法二:

添加以下类:

 1 import org.springframework.context.annotation.Configuration;
 2 import org.springframework.util.ResourceUtils;
 3 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
 4 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 5 
 6 @Configuration
 7 public class WebConfig extends WebMvcConfigurerAdapter {
 8     public void addResourcesHandlers (ResourceHandlerRegistry registry){
 9         registry.addResourceHandler("/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/templates/");
10         registry.addResourceHandler("/**").addResourceLocations(ResourceUtils.CLASSPATH_URL_PREFIX+"/static/");
11         super.addResourceHandlers(registry);
12     }
13 }

除了以上方法我还发现,更改文件名使其尽量短,有时也可以解决该问题。

springboot+thymeleaf不能读取静态资源的问题

原文:https://www.cnblogs.com/hong-yf/p/14654757.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!