在SpringBoot项目中出现了静态资源文件无法访问的情况,明明路径都正确,但是就访问不了
springboot访问静态资源,默认有两个默认目录:
一个是 src/mian/resource目录
一个是 ServletContext 根目录下(src/main/webapp)
有三种方式可以实现静态文件放行,任选其一即可
1.1 在application.properties配置静态文件放行spring.web.resources.static-locations=classpath:/static/1.2 在application.yml配置静态文件放行
spring:
resources:
static-locations: classpath:/static/
1.3 实现WebMvcConfigurer接口实现静态文件放行
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("*.xml
**/*.yml
false
这样就可以访问静态资源文件了



