【发布时间】: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