简体   繁体   English

Springboot 不提供静态内容

[英]Springboot does not serve static content

I am not able to access static content (angular app) or even a simple index.html file from spring-boot.我无法从 spring-boot 访问静态内容(angular 应用程序)甚至一个简单的 index.html 文件。 I keep getting 404 error.我不断收到 404 错误。 Spring is not serving me with those static files. Spring 没有为我提供这些静态文件。 I have the problem since I have upgraded to Spring-Boot 2.2.4.自从我升级到 Spring-Boot 2.2.4 以来,我遇到了问题。 I had to upgrade to counter Zip64 issue.我不得不升级以解决 Zip64 问题。

I have this line in my application.properties:我的 application.properties 中有这一行:

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

I also have my own staticResourceConfiguration class.我也有自己的 staticResourceConfiguration 类。

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.在我的 WebSecurity 类中,如果 url 路径与以下模式匹配,我应该提供以下内容。 The problem is localhost:8080/index.html works and localhost:8080 return 404问题是 localhost:8080/index.html 有效并且 localhost:8080 返回 404

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

You can use this answer to improve your own您可以使用此答案来改进自己的
Spring Boot not serving static content Spring Boot 不提供静态内容

or this或这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM