springfox-swagger启动项目 java.lang.OutOfMemoryError: Java heap space - Go语言中文社区

springfox-swagger启动项目 java.lang.OutOfMemoryError: Java heap space


项目环境

swagger2.6+springmvc 4.2.3

现象出现了递归 导致内存溢出

解决方法:

package com.smartkcenter.anyq.controller;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import com.fasterxml.classmate.TypeResolver;
import com.lengsun.framework.base.DataTableRequest;
import com.smartkcenter.anyq.model.AutoResponseHisDtlVw;
import com.smartkcenter.anyq.model.AutoResponseHisVw;
import com.smartkcenter.anyq.model.ResponseRepeatVw;
import com.smartkcenter.trn.model.KnowledgeEntryVw;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.AlternateTypeRule;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableWebMvc
@EnableSwagger2
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
    	 //添加过滤规则:移除嵌套对象
        TypeResolver typeResolver = new TypeResolver();
        AlternateTypeRule typeRule1 = new AlternateTypeRule(typeResolver.resolve(xxxxxx.class),typeResolver.resolve(Object.class));
        AlternateTypeRule typeRule2 = new AlternateTypeRule(typeResolver.resolve(xxxxxx.class),typeResolver.resolve(Object.class));
        AlternateTypeRule typeRule3 = new AlternateTypeRule(typeResolver.resolve(xxxxxx.class),typeResolver.resolve(Object.class));
        AlternateTypeRule typeRule4 = new AlternateTypeRule(typeResolver.resolve(xxxxxx.class),typeResolver.resolve(Object.class));
        AlternateTypeRule typeRule5 = new AlternateTypeRule(typeResolver.resolve(xxxxx.class),typeResolver.resolve(Object.class));
    	
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("系统-接口文档")
                        .description("about 接口")
                        .termsOfServiceUrl("http://xxxxxx")
                        .contact(new Contact("test", null, null))
                        .version("版本号:1.0")
                        .build()
                		)
                .alternateTypeRules(typeRule1,typeRule2,typeRule3,typeRule4,typeRule5)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xxxx.xxxxx.controller"))
                .paths(PathSelectors.any())
                .build();
    }

}

resolve()里面写的类就是你在controller里面方法,用到的类

这样就可以启动成功了。。

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_21101587/article/details/106496046
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-06-28 02:38:21
  • 阅读 ( 1303 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢