Java Spring数据弹性搜索和Spring数据Cassandra存在MapId问题
我试图让Spring数据Cassandra和Spring数据Elasticsearch一起工作。下面是我面临的问题Java Spring数据弹性搜索和Spring数据Cassandra存在MapId问题,java,spring,spring-data,
spring-data-elasticsearch,spring-data-cassandra,Java,Spring,Spring Data,
spring Data Elasticsearch,Spring Data Cassandra,我试图让Spring数据Cassandra和Spring数据Elasticsearch一起工作。下面是我面临的问题 org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.format.support.FormattingConversionService]: Factory method 'mvcConversionService' threw exce
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.format.support.FormattingConversionService]: Factory method
'mvcConversionService' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'personRepository': Invocation of init method failed;
nested exception is java.lang.IllegalArgumentException: Unsuppored ID type interface
org.springframework.data.cassandra.repository.MapId
我的存储库接口位于不同的包中,我已经用
@EnableElasticsearchRepositories(basePackages = "com.mycompany.mp.search.repo")
及
我使用了MappingCassandraConverter和org.springframework.data.elasticsearch.core.DefaultEntityMapper。elasticsearch模板是init,与此新的ElasticsearchTemplate类似(客户端,new DefaultEntityMapper())
我的Person对象看起来像这样
import org.springframework.data.cassandra.mapping.Table;
/**
* Created by allahbaksh_asadullah on 01/11/16.
*/
@Table(value = "person")
@Document(indexName = "person")
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Long id;
private String firstName;
private String lastName;
//Getters and Setters
}
如果我不使用@Document
注释标记Person.java,一切正常,但ElasticSearch将无法工作
使其工作的最佳方法是什么?如果您使用文档批注,请告诉我是否有任何错误。弹性搜索需要文档批注。是的,我正在使用@Document annotation。问题是您在存储库中使用
MapId
作为Id类型MapId
特定于Spring数据Cassandra,不适用于Elasticsearch。使用专用Id类型(@PrimaryKeyClass
)应该可以。如果使用文档批注,请告诉我是否有任何错误。弹性搜索需要文档批注。是的,我正在使用@Document annotation。问题是您在存储库中使用MapId
作为Id类型MapId
特定于Spring数据Cassandra,不适用于Elasticsearch。使用专用Id类型(@PrimaryKeyClass
)应该可以工作。
import org.springframework.data.cassandra.mapping.Table;
/**
* Created by allahbaksh_asadullah on 01/11/16.
*/
@Table(value = "person")
@Document(indexName = "person")
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Long id;
private String firstName;
private String lastName;
//Getters and Setters
}