【异常】swagger画面没显示controller

swagger画面没显示controller

效果

在这里插入图片描述

原代码

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(CommonCons.BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("springboot利用swagger构建api文档")
                .description("简单优雅的restful风格")
                .termsOfServiceUrl("http://blog.csdn.net/forezp")
                .version("1.0")
                .build();
    }

}

原因

启动类未加扫描根包注解,导致无法扫到

// 给启动类加注解,扫描根包
@SpringBootApplication(scanBasePackages = CommonCons.BASE_PACKAGE)
public class SpringclouddemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringclouddemoApplication.class, args);
    }
}

修正后效果

在这里插入图片描述

发布了37 篇原创文章 · 获赞 0 · 访问量 1137

猜你喜欢

转载自blog.csdn.net/qq_25046005/article/details/104144173
今日推荐