SpringBoot appears "No mapping for GET" static resources

  • In this case, assuming that the css, js, and fonts files are all under /resources/static, then add these two functions in 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);
        }   
    }

Guess you like

Origin blog.csdn.net/weixin_43844418/article/details/114045963