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

匆匆过客 提交于 2020-01-16 13:24:23

错误信息:

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”)注解启动再次访问就可以了

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!