问题
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.
I have this line in my application.properties:
spring.resources.static-locations=classpath:/resources/,classpath:/static/
I also have my own staticResourceConfiguration class.
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()
回答1:
You can use this answer to improve your own
Spring Boot not serving static content
or this
@Configuration
public class StaticResourceConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("file:/path/to/staticPage/");
}
}
来源:https://stackoverflow.com/questions/60119885/springboot-does-not-serve-static-content