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);
}
}