【问题标题】:SpringData and Elasticsearch - java.lang.StackOverflowError while using ignoreFieldsSpringData 和 Elasticsearch - 使用 ignoreFields 时出现 java.lang.StackOverflowError
【发布时间】:2017-02-21 00:04:56
【问题描述】:

我正在使用简单的关系(spring data elasticsearch)但是springboot正在抛出StackOverflowError

@Document(indexName = "users", type = "user")
public class User {
    @Id
    private String id;

    @Field(type= FieldType.Nested,ignoreFields={"users"})
    private Set<Group> groups = new HashSet<Group>();
}

@Document(indexName = "groups", type = "group")
public class Group {

    @Id
    String id;

    @Field(type = FieldType.Nested, ignoreFields ={"groups"})
    private Set<User> users = new HashSet<User>();
}

public interface UserRepository extends ElasticsearchRepository<User, String>{

}

public interface GroupRepository extends ElasticsearchRepository<Group, String> {

}

知道什么是问题吗?

代码来自https://github.com/spring-projects/spring-data-elasticsearch/tree/master/src/test/java/org/springframework/data/elasticsearch/entities

谢谢 拉詹

【问题讨论】:

  • 你找到解决这个问题的方法了吗?

标签: elasticsearch spring-boot spring-data spring-data-elasticsearch


【解决方案1】:

正如你所说:spring-boot 正在抛出 StackOverflowError。

这是因为 spring-boot 中没有安全措施或检测到循环依赖。

查看 spring-boot 源代码:MappingBuilder.java,当您的类 A 具有引用类 B 的 @Field 注释,具有引用类 A 的 @Field 注释时,循环永远不会中断。

【讨论】:

    猜你喜欢
    • 2020-06-17
    • 1970-01-01
    • 2017-07-13
    • 2012-05-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 2015-09-06
    • 2011-09-08
    相关资源
    最近更新 更多