错误:GET http://localhost:8080/static/img1/01.jpg 404

运行spring项目,打开html页面时,图片加载不出来,显示错误如下:

解决方法:在application.properties配置文件中加入以下代码:

#spring.web.resources.static-locations=classpath:/
#spring.mvc.static-path-pattern=/**

"spring.web.resources.static-locations"属性用于指定Spring框架查找静态资源的目录。默认情况下,Spring只会在"classpath:/static/"目录下查找静态资源,但您可以通过配置该属性来添加其他目录。

而"spring.mvc.static-path-pattern"属性用于指定哪些URL路径被视为静态资源请求。默认情况下,Spring会将以"/static/"开头的URL路径视为静态资源请求。通过配置该属性为"/**",您可以将所有请求路径都视为静态资源请求。

猜你喜欢

转载自blog.csdn.net/weixin_58707437/article/details/132652074