swagger-ui.html访问不了,页面报错404,解决办法

Published on with 0 views and 0 comments

问题描述

Springboot 整合 Swagger 后,查看生成Api文档:发现 swagger-ui.html访问不了,页面报错404

解决办法

SwaggerConfig配置类重写addResourceHandlers方法

public class SwaggerConfig implements WebMvcConfigurer {
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}

标题:swagger-ui.html访问不了,页面报错404,解决办法
作者:dduan
地址:https://dduan.site/articles/2021/08/30/1630315285540.html