springboot集成swagger,出现 No mapping for GET /swagger-ui.html的错误
在尝试降低springboot版本和swagger版本都无法解决这个问题后
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
在SpringBoot项目引入Swagger2后,在浏览器地址里输入地址:http://ip:port/swagger-ui.html 报错:
控制台出现这样子的错误:swagger No mapping for GET /swagger-ui.html
解决办法:
1、在配置类中继承WebMvcConfigurationSupport类,重写addResourceHandlers方法
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("doc.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
访问成功
————————————————
版权声明:本文为CSDN博主「Aige_hml」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Aige_hml/article/details/124017391