springboot整合Swagger2弹窗提示Unable to infer base url. This is common when using dynamic servlet registra

错误信息:

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

访问swagger-ui.html弹窗
在这里插入图片描述
根据错误信息在网上找了说是加上@EnableSwagger2注解的但是这个注解我是有的

@Configuration
@EnableSwagger2
public class Swagger2 {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.admin01"))
                .paths(PathSelectors.any())
                .build();
    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2构建RESTful APIs")
                .description("更多Spring Boot相关文章请关注:http://www.zing-tech.com/")
                .termsOfServiceUrl("http://www.zing-tech.com")
                .contact("ygl")
                .version("1.0")
                .build();
    }
}

随后发现是spring没有扫描到Swagger2配置类,在启动类上加上@ComponentScan(“com.example.config”)注解启动再次访问就可以了


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