SpringBoot整合Swagger无法访问swagger-ui.html的问题

在整合Swagger时访问默认的路径:http://localhost:8080/swagger-ui.html,出现404问题,根据查看,发现是相关资源被拦截了,于是配置下就好了

@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 解决swagger被拦截的问题
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
   		registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

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

}

最简洁的就是直接配置/*,放开所有的请求。亲测试有效,具体为啥原因,因为是小白没看懂

参考地址:https://blog.csdn.net/a15119273009/article/details/107687834/
参考地址:https://blog.csdn.net/ljm_csdn/article/details/87615670


版权声明:本文为mrhaoxiaojun原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。