当前位置: 代码网 > it编程>编程语言>Java > springboot静态资源(static)无法访问问题404及解决过程

springboot静态资源(static)无法访问问题404及解决过程

2026年05月15日 Java 我要评论
springboot 静态资源(static)无法访问问题404(如果使用了拦截器)检查配置的拦截器是否对静态资源放行@overridepublic boolean prehandle(httpser

springboot 静态资源(static)无法访问问题404

(如果使用了拦截器)

检查配置的拦截器是否对静态资源放行

@override
public boolean prehandle(httpservletrequest request, httpservletresponse response, object handler) throws exception {
 	// 如果不是映射到方法直接通过,防止静态资源被拦截
 	if (!(handler instanceof handlermethod)) {
       return true;
 	}
  	...
}

检查继承webmvcconfigureradapter类

或实现webmvcconfigure 接口中是否配置了静态资源放行

(就是使用@enablewebmvc注解的地方)

	/**
     * ·
     * 静态资源映射
     */
    @override
    public void addresourcehandlers(resourcehandlerregistry registry) {
        registry.addresourcehandler("/**").addresourcelocations("classpath:/meta-inf/resources/")
                .addresourcelocations("classpath:/resources/").addresourcelocations("classpath:/static/")
                .addresourcelocations("classpath:/public/");
        super.addresourcehandlers(registry);
    }

检查pom.xml中build的配置

(如果仍无法访问)

<resources>
    <resource>
       <directory>src/main/webapp</directory>
     </resource>
     <resource>
       <directory>src/main/resources</directory>
       <filtering>true</filtering>
     </resource>
</resources>

如果有权限框架

如shiro或者spring security 自行配置请求过滤策略

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com