当前位置:   article > 正文

springboot 使用Swagger2 报错:No mapping for GET /swagger-ui.html_openapi no mapping for get /swagger-ui/index.html

openapi no mapping for get /swagger-ui/index.html

项目场景:No mapping for GET /swagger-ui.html

提示:这里简述项目相关背景:

No mapping for GET /swagger-ui.html

问题描述

提示:这里描述项目中遇到的问题:
访问:http://localhost:9090/swagger-ui.html
在这里插入图片描述
报404,控制台信息给出
在这里插入图片描述

原因分析:

提示:这里填写问题的分析:

这是springboot启动类在@EnableWebMvc的注释之下,原先swagger2的默认地址失效了,所有需要重新配置

@SpringBootApplication
@EnableWebMvc
@EnableTransactionManagement
@EnableSwagger2
public class SpringbootVueProjectApplication {

  public static void main(String[] args) {
    SpringApplication.run(SpringbootVueProjectApplication.class, args);
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

解决方案:

在SwaggerConfig配置类中实现 WebMvcConfigurer,重写addResourceHandlers方法

@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/");
        WebMvcConfigurer.super.addResourceHandlers(registry);

    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

然后就可以了
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/99127
推荐阅读
相关标签
  

闽ICP备14008679号