springfox: Slow scanning time on SpringMVC application
Hey guys!
I’m currently using the 2.9.2 version on Springfox and I’m facing long wait times deploying my application, just when springfox starts to scan for api listing references and generating unique operations. If I add “nickname” on @ApiOperation to avoid the unique operation generation, the slow time stays the same.
This is my SwaggerConfiguration.java:
@Configuration
@EnableSwagger2
public class SwaggerConfiguration extends WebMvcConfigurerAdapter {
private static final String RESOURCE_PACKAGE = "br.com.finchsolucoes.xgracco.application.api.resource";
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
@Bean
private Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.useDefaultResponseMessages(false)
.groupName("Api")
.select()
.apis(RequestHandlerSelectors.basePackage(RESOURCE_PACKAGE))
.apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(regex( "/api.*"))
.build()
.ignoredParameterTypes(AuthenticationPrincipal.class)
.globalOperationParameters(
Collections.singletonList(
new ParameterBuilder()
.name("Authorization")
.description("Bearer token")
.modelRef(new ModelRef("string"))
.parameterType("header")
.required(true)
.build()));
.apiInfo(metaDados());
}
private ApiInfo metaDados() {
return new ApiInfoBuilder()
.title("X-Gracco API")
.description("Módulo Gestão Processos.")
.version("5.4.0")
.contact(new Contact("Finch Soluções", "http://www.finchsolucoes.com.br", "comercial@finchsolucoes.com.br"))
.build();
}
}
I was using the 2.4.0 version before, it deploys really fast, but it is very slow to fetch de JSON data from /v2/api-docs to swagger-ui.html. On the other side, the swagger-ui.html works like a charm on 2.9.2, but the deploy doesn’t.
Any help is appreciated.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 6
- Comments: 33 (12 by maintainers)
Commits related to this issue
- Issue #2881. Do not resolve dependencies which have already been resolved. — committed to sgri/springfox by sgri 5 years ago
- Issue #2881. Use an import per class according to code review. — committed to sgri/springfox by sgri 4 years ago
While my pull request fixed issue with 2.9.2, it is required, but not sufficient for 3.0.0 because version 3.0.0-SNAPSHOT has introduced another bottleneck in springfox.documentation.spring.web.scanners.ApiModelReader#mergeModelBranch which has been re-written since 2.9.2 was released. ApiModelReader#mergeModelBranch in version 3.0.0 has @SuppressWarnings({“CyclomaticComplexity”, “NPathComplexity”}) annotation which indicates that some code inspection tool detected that code is potentially very slow, and that warning should not have been ignored.
I could not fix it in version 3.0.0, merging algorithm is fairly complicated. Version 3.0.0-SNAPSHOT is significantly slower than 2.9.2 because it has two bottlenecks, and Springfox initialization takes 5 minutes compared to 40 seconds with version 2.9.2 for 158 REST functions. That makes version 3.0.0-SNAPSHOT completely unusable in large projects with more than 150 REST functions.
So the only option to get it fixed is to make a hotfix release 2.9.3 based on 2.9.2.