Java Spring Data Mongo 1.5 的“循环发现”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24381466/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 11:52:43  来源:igfitidea点击:

"Cycle found" with Spring Data Mongo 1.5

javaspringspring-dataspring-data-mongodb

提问by Mistic

I have a project perfectly running with Spring Data MongoDB 1.4.2. I tried to update to 1.5.0 and I get this error during autowiring (extract) :

我有一个与 Spring Data MongoDB 1.4.2 完美运行的项目。我尝试更新到 1.5.0,但在自动装配(提取)期间出现此错误:

Caused by: org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$CyclicPropertyReferenceException: Found cycle for field 'rules' in type 'Filter' for path 'filter.rules'
at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$CycleGuard.protect(MongoPersistentEntityIndexResolver.java:370) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$2.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:144) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
at org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$2.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:138) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:294) ~[spring-data-commons-1.8.0.RELEASE.jar:na]

引起:org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$CyclicPropertyReferenceException: 在 org.springframework.data.mongodb.core.index 的路径“filter.rules”的“过滤器”类型中找到字段“规则”的循环
.MongoPersistentEntityIndexResolver$CycleGuard.protect(MongoPersistentEntityIndexResolver.java:370) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
在 org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$istIndexResolver. .java:144) ~[spring-data-mongodb-1.5.0.RELEASE.jar:na]
在 org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver$2.doWithPersistentProperty(MongoPersistentEntityIndexResolver.java:138) ~[spring -data-mongodb-1.5.0.RELEASE。罐子:无]
在 org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:294) ~[spring-data-commons-1.8.0.RELEASE.jar:na]

I have a repository "RulesDAO" simply extending "MongoRepository". It manages an entity named "Rule". This entity has some basic fields and a "Filter" field. And this Filter class contains a list of Filter (which can be empty).

我有一个存储库“RulesDAO”,只是扩展了“MongoRepository”。它管理一个名为“Rule”的实体。该实体有一些基本字段和一个“过滤器”字段。而这个 Filter 类包含一个 Filter 列表(可以为空)。

@Document(collection="rules")
public class Rule {

    @Id private String id;

    private String name;

    // other fields

    private Filter filter;

}

public class Filter {

    // for groups
    private String condition;

    private List<Filter> rules = new ArrayList<Filter>();


    // for query
    private String field;

    private String value;

}

("rules" is not a perfect name, but it has to be named this way for MVC binding)

(“规则”不是一个完美的名称,但它必须以这种方式命名以用于 MVC 绑定)

So the Filter.rules property is interpreted as a cycle where it isn't ! (well in my understanding of the term "cycle")

所以 Filter.rules 属性被解释为一个循环,它不是!(在我对“周期”一词的理解中)

Is it a bug in the release or is there a new "flag" for this usecase ?

这是版本中的错误还是此用例有新的“标志”?

Thanks

谢谢



For the background story, the Filter class can be either a leaf or a node of a tree used to build complex Criteria, it is builded from the JSON of a jQuery plugin of mines http://mistic100.github.io/jQuery-QueryBuilder

对于背景故事,Filter 类可以是用于构建复杂 Criteria 的树的叶子或节点,它是从地雷http://mistic100.github.io/jQuery-QueryBuilder的 jQuery 插件的 JSON 构建的

回答by Christoph Strobl

The given types contain a strcuture potentially causing infinite loops while trying to resolve index information and/or reading values from the store. During startup domain types as well as generic type information of Collections are inspected. This points out the cycle mentioned in the resulting error.

在尝试解析索引信息和/或从存储读取值时,给定的类型包含可能导致无限循环的结构。在启动期间检查域类型以及集合的通用类型信息。这指出了由此产生的错误中提到的循环。

Rule -> Filter -> Filter.rules
          ^                |
          |                |
          +----------------+

Though the error should not prevent the container from starting - should only be printed to the log. Maybe you addtionally ran into DATAMONGO-949and want to give the current 1.5.1-SNAPSHOT a spin.

虽然错误不应该阻止容器启动 - 应该只打印到日志中。也许您还遇到了DATAMONGO-949并想尝试一下当前的 1.5.1-SNAPSHOT。

Please feel free to open a ticket.

请随意开票

回答by sorav sahu

You are using:private List<Filter> rules = new ArrayList<Filter>();

您正在使用:private List<Filter> rules = new ArrayList<Filter>();

change this to:private List<?> child;

将此更改为:private List<?> child;

I was facing same problem but after using this the code is working fine without error.

我遇到了同样的问题,但使用此代码后,代码工作正常,没有错误。

回答by Hank

Your code is correct. That log message is just INFOlevel to tell you that there is potential cycle reference in your code.

你的代码是正确的。该日志消息只是INFO告诉您代码中存在潜在的循环引用。

You could ignore that annoying message by turning logger off. In case your are using Spring Boot, add this to your application.propertiesfile: logging.level.org.springframework.data.mongodb.core.index=OFF

您可以通过关闭记录器来忽略这条烦人的消息。如果您使用的是 Spring Boot,请将其添加到您的application.properties文件中: logging.level.org.springframework.data.mongodb.core.index=OFF