注入一个继承WebMvcConfigurationSupport的配置类,并重写addResourceHandlers方法

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport{

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/","file:./static/");
    }
}

原文链接:https://miansen.wang/2019/01/06/1/