Springboot No mapping for GET xxx

正常情况下Springboot项目静态资源在static目录下直接通过目录(/xxx)就可以访问,但是项目中实现了配置类(WebConfig),则会在配置类中寻找,由于找不到则会报错,从而导致前端加载异常。

要解决这个问题只需在配置类中覆写addResourceHandlers方法即可。

public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
    }
}
原文地址:https://www.cnblogs.com/x-1204729564/p/15394301.html