SpringBoot中測試Elasticsearch,在測試ElasticsearchRepository文檔操做中的查詢時報錯org.springframework.data.elastics...

問題描述html

在SpringBoot中測試Elasticsearch的時候,當測試ElasticsearchRepository的文檔操做的時候,在調用find()查詢方法時報錯,錯誤以下java

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.zmx.elasticsearch.pojo.Item` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (String); line: 1, column: 2] at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67) at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1452) at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1028) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1297) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159) at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4013) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3004) at org.springframework.data.elasticsearch.core.DefaultEntityMapper.mapToObject(DefaultEntityMapper.java:82) at org.springframework.data.elasticsearch.core.AbstractResultMapper.mapEntity(AbstractResultMapper.java:43) ... 56 more
 

緣由spring

這是由於在實體類Item中爲了方便實例化添加了一個有參構造函數,致使JVM不能添加默認的無參構造函數了,可是jackson的反序列化須要使用無參構造函數,因此報錯!app

解決elasticsearch

在實體類Item中添加一個無參構造函數就能夠了!函數

引用測試

https://www.cnblogs.com/yucfeng/p/8932089.html#4131391 更加詳細的介紹能夠參考這個朋友的文章!spa

相關文章
相關標籤/搜索