Springboot不提供静态内容

编程入门 行业动态 更新时间:2024-10-12 12:34:14
本文介绍了Springboot不提供静态内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我无法从spring-boot访问静态内容(角度应用程序),甚至无法访问简单的index.html文件.我不断收到404错误.Spring没有为我提供这些静态文件.我有问题,因为我已经升级到Spring-Boot 2.2.4.我不得不升级以解决Zip64问题.

I am not able to access static content (angular app) or even a simple index.html file from spring-boot. I keep getting 404 error. Spring is not serving me with those static files. I have the problem since I have upgraded to Spring-Boot 2.2.4. I had to upgrade to counter Zip64 issue.

我的application.properties中有这一行:

I have this line in my application.properties:

spring.resources.static-locations=classpath:/resources/,classpath:/static/

我也有自己的staticResourceConfiguration类.

I also have my own staticResourceConfiguration class.

在我的WebSecurity类中,如果url路径与以下模式匹配,则应具有以下内容可提供静态内容.问题是localhost:8080/index.html可以正常工作,而localhost:8080返回404

In my WebSecurity class, i have the following which is supposed to serve static content if the url path is matched to the below patterns. The problem is localhost:8080/index.html works and localhost:8080 return 404

.antMatchers(HttpMethod.GET, "/**","/**/*.html", "/static/favicon.ico", "/**/*.js", "/**/*.js.map", "/**/*.css", "/**/*.png", "/**/*.jpg", "/**/*.jpeg", "/**/*.gif", "/**/*.ttf", "/**/*.json", "/**/*.woff", "/**/*.woff2", "/**/*.eot", "/**/*.svg","/**/*.json").permitAll()

推荐答案

您可以使用此答案来改进自己的答案 Spring Boot不提供静态内容

You can use this answer to improve your own Spring Boot not serving static content

或此

@Configuration public class StaticResourceConfiguration extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/**").addResourceLocations("file:/path/to/staticPage/"); } }

更多推荐

Springboot不提供静态内容

本文发布于:2023-11-14 04:06:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静态   内容   Springboot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!