springboot集成swagger报错:Unable to infer base url.

访问:http://localhost:8001/swagger-ui.html
报错内容:

Unable to infer base url. This is common when using dynamic servlet registration or when the API is behind an API Gateway. The base url is the root of where all the swagger resources are served. For e.g. if the api is available at http://example.org/api/v2/api-docs then the base url is http://example.org/api/. Please enter the location manually: 

在这里插入图片描述
解决办法:
1.检查swagger配置类上是否有一下注解

@Configuration//配置类
@EnableSwagger2//swagger注解

在这里插入图片描述
2.检查springboot的启动类上是否有以下注解:

@SpringBootApplication
@ComponentScan(basePackages = {"com.sun"})//扫描包名为com.sun的部分,实现多模块应用
@EnableSwagger2

在这里插入图片描述
完成后,再访问:http://localhost:8001/swagger-ui.html,
在这里插入图片描述


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