【问题标题】:Java Spring Swagger Startuptime StartupbehaviourJava Spring Swagger 启动时间 启动行为
【发布时间】:2019-06-23 19:11:38
【问题描述】:

我有一个 Springboot 应用程序,我在其中集成了 Swagger 以创建 REST 文档。

使用 swagger 时,我的启动时间会显着增加 5 倍。我有 30 秒没有 swagger。 2分钟加上大摇大摆。

此外,在启动时间下方的剪辑中列出的案卷变得无穷无尽! - 这是不行的。

我的问题是无休止的启动时间 + google guava 的内存使用异常。

为什么会这样?我究竟做错了什么?缺失点在哪里?为什么 API 不能保护我免受非常错误的设置?

感觉 swagger 一方面是记录其余 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

我在某处了解到需要交换 google 的 guava 库;我做了: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;
}

【问题讨论】:

    标签: java spring swagger springfox


    【解决方案1】:

    尝试使用

    中指定的最新 swagger-ui(swagger-js 2.1.17)

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

    【讨论】:

    • 我去看看。第一条评论于 2016 年 1 月 27 日开始。谢谢......如果有人在 java / spring 上认真使用它,我会很感兴趣。
    • 我没有使用更高版本的 2.9.2 吗?如果我猜对了,您说的是一些 js 库(我猜是因为提到了 swagger-js 2.1.17)。我遇到的问题发生在 java 启动时,并且不处理在浏览器中显示它。它更多地处理 swagger/springfox 收集数据以创建 gui/html 以便显示。
    • swagger-ui 版本 3.18.3
    • Hey Mebin,我很困惑...我在我引用 io.springfox 库的 maven 设置上运行 java/spring。他们的最大版本控制目前为 2.9.2,可在此处看到 mvnrepository.com/artifact/io.springfox/springfox-swagger2 您还有其他设置方法吗?那将是Maven设置。在哪里查找?请参阅此处如何在 maven 的 pom.xml 中引用这些库:pastebin.com/9WMr1fET
    猜你喜欢
    • 1970-01-01
    • 2021-04-25
    • 2017-01-07
    • 2023-02-16
    • 1970-01-01
    • 2021-01-15
    • 2022-11-11
    • 1970-01-01
    • 2016-06-13
    相关资源
    最近更新 更多