El interceptor de configuración de Springboot aparece "Sin mapeo para GET" recursos estáticos

Cuando esto suceda, suponga que los archivos css, js y fonts están todos en /resources/static, luego agregue estas dos funciones en webConfig.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);
        }
    }

Supongo que te gusta

Origin blog.csdn.net/weixin_42838061/article/details/123787785
Recomendado
Clasificación