繁体   English   中英

Spring data elasticsearch:throws MappingInstantiationException: Failed to instantiate java.util.Set using constructor NO_CONSTRUCTOR with arguments

[英]Spring data elasticsearch:throws MappingInstantiationException: Failed to instantiate java.util.Set using constructor NO_CONSTRUCTOR with arguments

我正在将应用程序迁移到最新的 spring 引导版本(使用 gradle spring-boot-dependencies 和版本 2.5.4)。

我有一个名为Customer的实体,它用@Document(indexName = "customer")注释; 和另一个用@Document(indexName = "address")注释的实体Address 客户 class 有private Set<Address> addresses = new HashSet<>()

从存储库调用List hits = elasticsearchTemplate.search(nativeSearchQuery, Customer.class)时出现以下错误。

org.springframework.data.mapping.model.MappingInstantiationException:无法实例化 java.util.Set 使用带有 ZDBC11CAA5BDA9E77E6FB4DABD8 的构造函数 NO_CONSTRUCTOR

如果我遵循类似的 MONGO 建议Failed to instance java.util.Set 使用带有 arguments 的构造函数 NO_CONSTRUCTOR并声明为private HashSet<Address> addresses = new HashSet<>() ,它会起作用。 我无法遵循这一点,因为我们有数百个实体,并且使用 JPA 元模型构建的 JPA 标准映射失败。

请注意,我已经查看了以下 2 个线程并觉得它有所不同:

  1. 从 3.x 到 4.x 的 Spring 数据弹性迁移的索引问题
  2. Spring 数据 elasticsearch:在 POJO 接口 class 上使用 @Document 注释不起作用

如果您正在寻找示例存储库: https://gitlab.com/mvallapuneni/spring-es-sample

任何帮助表示赞赏...

java.util.Set 是一个接口,而不是 class。 接口没有构造函数,它们与“实现”(具有操作代码方法)接口的 class 相连。 接口中的所有方法签名都是抽象的,它们没有代码,只有实现 class 提供的方法的签名。 例如 HashSet 是实现 java.util.Set 的 class 参见 API 文档在其页面顶部的“所有已知的实现类”

您的 HashSet 是私有,它必须使用私有方法来调用它,例如 set 或 get etc。

为了冒险猜测 List 必须成为一个 Set 但 List 被实例化并且 Set 是一个等待的变量。 在私有方法的代码中的某个地方,这就像(形象地)......

private Set<Address> addresses = (Set<Address>)(Collection<Address>)elasticsearchTemplate.search(nativeSearchQuery, Customer.class);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM