SpringBoot出现“No mapping for GET“静态资源的情况

  • 出现这种情况,假定css,js,fonts文件都在/resources/static下,那么在MyMvcConfig.java内加上这两个函数
 private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
    
    
            "classpath:/META-INF/resources/", "classpath:/resources/",
            "classpath:/static/", "classpath:/public/"
    };


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    
    
        if (!registry.hasMappingForPattern("/webjars/**")) {
    
    
            registry.addResourceHandler("/webjars/**").addResourceLocations(
                    "classpath:/META-INF/resources/webjars/");
        }
        if (!registry.hasMappingForPattern("/**")) {
    
    
            registry.addResourceHandler("/**").addResourceLocations(
                    CLASSPATH_RESOURCE_LOCATIONS);
        }   
    }

猜你喜欢

转载自blog.csdn.net/weixin_43844418/article/details/114045963