簡體   English   中英

Java Spring Swagger 啟動時間 啟動行為

[英]Java Spring Swagger Startuptime Startupbehaviour

我有一個 Springboot 應用程序,我在其中集成了 Swagger 以創建 REST 文檔。

使用 swagger 時,我的啟動時間會大幅增加 5 倍。沒有 swagger 時我有 30 秒。 2 分鍾加上 swagger。

此外,在啟動時間下方的剪輯中列出的案卷也變得無窮無盡。 - 這是不行的。

我的問題是無休止的啟動時間 + google guava 使用 memory 的例外情況。

為什么會這樣? 我究竟做錯了什么? 缺失點在哪里? 為什么 API 不能保護我免受非常錯誤的設置?

感覺 swagger 一方面是記錄 rest API 的第一工具,但使用它對我來說感覺很古老。

一些設置信息(位於 maven pom.xml):
- org.springframework.boot; spring-boot-starter-parent; 1.5.5.發布
- io.springfox; springfox-swagger2; 2.9.2
- io.springfox; springfox-swagger-ui; 2.9.2

我在某處撿到需要交換谷歌的番石榴庫; 我做了: https://github.com/springfox/springfox/issues/2616#issuecomment-412811912

swagger/springfox 真的非常適合用於記錄來自 Spring 的 API 嗎? - 呈現文檔的替代方法是什么?

@Configuration
@EnableSwagger2
public class Swagger2UiConfiguration extends WebMvcConfigurerAdapter {
  ...
  @Bean(name="restPublicSwaggerV1Api")
  public Docket publicV1Api(BuildProperties build) {

    final ApiInfoBuilder apiInfo = new ApiInfoBuilder()
            .title(build.getName())
            .description("Description for public API")
            .version( build.getVersion() );

    final long TIME = System.currentTimeMillis();

    final Docket docket = new Docket(DocumentationType.SWAGGER_2)
            .groupName( "public-v1" )
            .apiInfo( apiInfo.build() )
            .select()
            .apis( (wmrh)->{ // springfox.documentation.spring.web.WebMvcRequestHandler

                final StringBuffer sb = new StringBuffer();
                sb.append( wmrh.getClass().getTypeName()  +"\n\t"+ wmrh );
                final RequestHandlerKey rhk = wmrh.key();

                boolean result = false;

                for( String pathMapping : rhk.getPathMappings() ) {
                    sb.append( "\n\t-> "+ pathMapping );
                    result |= pathMapping.startsWith( "/api/public/" );
                }

                sb.append( "\n\t=>> "+ result +", time: "+ Util.formatTime( System.currentTimeMillis() - TIME ) +" after start." );

                LOG.debug( sb.toString() );

                return result;
            } )
            .paths( (p)->{ return true; } )
            .build();

    LOG.debug( "instantiated: {}", docket );
    return docket;
}

嘗試使用中指定的最新swagger-ui(swagger-js 2.1.17)

https://github.com/swagger-api/swagger-ui/issues/1919

在多對多關系中使用 @JsonIgnore

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM