【问题标题】:Swagger Recursively resolving dependencies for type (Infinite loop)Swagger 递归解析类型的依赖关系(无限循环)
【发布时间】:2020-01-05 09:03:50
【问题描述】:

我们想将 Swagger 用于现有的 Spring-boot 项目(> 70 模型,> 250 端点),但我们遇到了一个问题,即应用程序无法启动并且在设置 Swagger 时进入无限循环。

  • 日志
...
[DEBUG] 2020-01-04 23:28:32.500 Recursively resolving dependencies for type X;
[DEBUG] 2020-01-04 23:28:32.500 Adding type X2; for parameter x2
[DEBUG] 2020-01-04 23:28:32.501 Recursively resolving dependencies for type X2;
[DEBUG] 2020-01-04 23:28:32.501 Adding type Ljava/util/List<X3>; for parameter x3s
[DEBUG] 2020-01-04 23:28:32.501 Adding collectionElement type X3;
[DEBUG] 2020-01-04 23:28:32.501 Recursively resolving dependencies for collectionElement type X3;
[DEBUG] 2020-01-04 23:28:32.501 Adding type Ljava/util/List<X4;>; for parameter x4s
[DEBUG] 2020-01-04 23:28:32.501 Adding collectionElement type X4;
[DEBUG] 2020-01-04 23:28:32.501 Recursively resolving dependencies for collectionElement type X4;
...
  • POM
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>
...
    <dependencies>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        ....
    <dependencies>

感谢任何帮助,甚至是一些关于如何深入研究这个问题的提示,因为日志没有帮助,我不知道从哪里开始! 如果您需要更多详细信息,请告诉我。

【问题讨论】:

    标签: java spring spring-boot swagger springfox


    【解决方案1】:

    有(有)同样的问题,由于弹簧魔法,我们最终使用 id 而不是整个对象的解决方法。只需为导致问题的参数添加@ApiIgnore,然后手动添加ApiImplicitParamlike

    @ApiImplicitParam(
        required = true,
        value = "XxxId, of provided Xxx. Not Required",
        paramType = "query",
        dataType = "int"
    )
    @GetMapping(value = ["/XXX_PATH"])
    fun getYyy(
        @ApiIgnore @RequestParam(required = false, value = Xxx_ID) xxx: Xxx?
    ): List<Yyy>
    

    我想如果你真的需要在文档中包含整个对象而不仅仅是它们的 ID,你需要阅读 dataType 上的文档。祝你好运。

    【讨论】:

    • 据我了解,所以我应该检查所有有此问题的 api 端点(使用对象而不是 ids)并进行更改,对吗?还有一点,我怎么能弄清楚哪些端点有这个问题,因为日志不是很有帮助(我有> 250个端点!),非常感谢。
    • 我不会说这很容易,也许还有更好的方法。在我们的案例中,我们从乞讨中招摇过市,所以我们注意到有一个改动破坏了它,而且很快就修复了。作为一般方法:了解您的域并检查您在 API 中公开的对象中的循环在哪里。如果您的数据库实体与 REST 资源非常相似,那么数据库自动生成的图表会很有帮助,这对于大多数应用程序都是如此。作为其他方法,尝试注释掉整个控制器/删除包并使用二分法查找有问题的。
    【解决方案2】:

    您可以全局忽略特定问题的类。

    docket.ignoredParameterTypes(Order.class)

    https://springfox.github.io/springfox/docs/current/#q18

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-06
      • 1970-01-01
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 2014-05-06
      • 1970-01-01
      • 2016-10-06
      相关资源
      最近更新 更多