Springboot不提供静态内容 [英] Springboot does not serve static content

查看:92
本文介绍了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不提供静态内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆