Spring-Data-Elastic Search and Spring-Data-Cassand

2019-07-25 01:12发布

问题:

I am trying to have Spring-Data-Cassandra and Spring-Data-Elasticsearch work together. Below is the problem which I am facing.

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

My Repositories interfaces are in different packages and I have marked the with

@EnableElasticsearchRepositories(basePackages = "com.mycompany.mp.search.repo") 

and

@EnableCassandraRepositories(basePackages = { "com.infy.mycompany.repository" })

I have used MappingCassandraConverter and org.springframework.data.elasticsearch.core.DefaultEntityMapper. The elasticsearch template is init like this new ElasticsearchTemplate(client, new DefaultEntityMapper());

My Person object looks like this.

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
}

If I don't mark my Person.java with the @Document annotation things works fine but ElasticSearch will not work then.

What is the best way make it work?