当前位置:   article > 正文

springboot集成swagger,出现 No mapping for GET /swagger-ui.html的错误

no mapping for get /swagger-ui.html

在尝试降低springboot版本和swagger版本都无法解决这个问题后

  1. <dependency>
  2. <groupId>io.springfox</groupId>
  3. <artifactId>springfox-swagger2</artifactId>
  4. <version>2.9.2</version>
  5. </dependency>
  6. <dependency>
  7. <groupId>io.springfox</groupId>
  8. <artifactId>springfox-swagger-ui</artifactId>
  9. <version>2.9.2</version>
  10. </dependency>

在SpringBoot项目引入Swagger2后,在浏览器地址里输入地址:http://ip:port/swagger-ui.html 报错:

 控制台出现这样子的错误:swagger  No mapping for GET /swagger-ui.html

解决办法:

 1、在配置类中继承WebMvcConfigurationSupport类,重写addResourceHandlers方法

  1. @Override
  2. public void addResourceHandlers(ResourceHandlerRegistry registry) {
  3. registry.addResourceHandler("doc.html")
  4. .addResourceLocations("classpath:/META-INF/resources/");
  5. registry.addResourceHandler("swagger-ui.html")
  6. .addResourceLocations("classpath:/META-INF/resources/");
  7. registry.addResourceHandler("/webjars/**")
  8. .addResourceLocations("classpath:/META-INF/resources/webjars/");
  9. }

 访问成功

 

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

闽ICP备14008679号