静态资源访问以及swagger.html 404的配置文件

建了个springboot项目写几个接口,对外提供json格式接口,内部写个页面验证时,发现静态资源404了,好久没写非前后端分离了,故记录一下

thymeleaf:
   mode: HTML
   prefix: classpath:/templates/
   suffix: .html
   cache: false
 mvc:
   static-path-pattern: /static/**
@Configuration
@Component
public class MvcConfig extends WebMvcConfigurationSupport {
    private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
            "classpath:/META-INF/resources/", "classpath:/resources/",
            "classpath:/static/", "classpath:/public/",
            "classpath:/META-INF/resources/webjars/springfox-swagger-ui/"};


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

    }
}
posted @ 2022-06-14 16:31  Leejk  阅读(273)  评论(0编辑  收藏  举报