个人技术分享

偷懒太久了,这两天跟着B站上的视频做项目,遇到了一个小坑

项目是一个SpringBoot前后端一体的项目,静态资源全部在resource/static和resource/views下面,并且yml文件设置了static-localtions配置

spring:
  resources:
    static-locations: classpath:/static/,classpath:/views/

在SpringBoot版本在2.5.x版本,在项目启动后直接使用localhost:80可以进行访问,

但是升级SpringBoot版本在2.6.13之后,同样方法访问则报404错误

原因:

(没有研究过SpringBoot源码和迭代过程,仅为个人通过询问A.I.工具得出)

SpringBoot升级2.6.x后,path设置访问改变,可能是因为Spring版本导致

解决方法:

将静态文件路径配置修改为以下即可

spring:
 web:
   resources:
     static-locations: classpath:/static/,classpath:/views/