在线教育项目-Swagger整合遇到的问题-Unable to infer base url....

问题

访问 http://localhost:8001/swagger-ui.html 一直有页面提示且关不掉。
在这里插入图片描述

解决

大家都说是因为拦截器的原因,我试过好多方法,还是觉得在application方法上添加注解最简单:@EnableSwagger2

@SpringBootApplication
//@EnableSwagger2
@ComponentScan(basePackages = {"com.xxx"})
public class EduApplication {
    public static void main(String[] args) {
        SpringApplication.run(EduApplication.class,args);
    }
}
@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket webApiConfig(){
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();
    }

    private ApiInfo webApiInfo(){
        return new ApiInfoBuilder()
                .title("xxx")
                .description("xxx")
                .version("1.0")
                .contact(new Contact("xxx", "http://xxx.com/", "[email protected]"))
                .build();
    }
}

结果

和预期还是有些差别,但是能用了。
在这里插入图片描述

反馈

第二天,发现是因为application的模块没有引入swagger所在模块的依赖,我人傻了。
不用在application方法上添加注解@EnableSwagger2。
swagger 2.7.0 在上述写法上没有问题。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43845524/article/details/106531165