Alessandro Suglia
Alessandro Suglia

Reputation: 1927

No converter found capable of converting from type [java.lang.String] to type [org.springframework.data.solr.core.geo.Point]

I am trying to use spring-data-solr in order to access to my Solr instance through my Spring boot application. I have the following bean class:

@SolrDocument(solrCoreName = "associations")
public class Association implements PlusimpleEntityI {
    @Id
    @Indexed
    private String id;
    @Indexed
    private String name;
    @Indexed
    private Point location;
    @Indexed
    private String description;
    @Indexed
    private Set<String> tags;
    @Indexed
    private Set<String> topics;
    @Indexed
    private Set<String> professionals;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Point getLocation() {
        return location;
    }

    public void setLocation(Point location) {
        this.location = location;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Set<String> getTags() {
        return tags;
    }

    public void setTags(Set<String> tags) {
        this.tags = tags;
    }

    public Set<String> getTopics() {
        return topics;
    }

    public void setTopics(Set<String> topics) {
        this.topics = topics;
    }

    public Set<String> getProfessionals() {
        return professionals;
    }

    public void setProfessionals(Set<String> professionals) {
        this.professionals = professionals;
    }
}

I have implemented the following repository in order to access to the related information:

public interface AssociationsRepository extends SolrCrudRepository<Association, String> {
}

I have created a configuration class which looks like the following one:

@Configuration
@EnableSolrRepositories(basePackages = {"com.package.repositories"}, multicoreSupport = true)
public class SolrRepositoryConfig {
    @Value("${solr.url}")
    private String solrHost;

    @Bean
    public SolrConverter solrConverter() {
        MappingSolrConverter solrConverter = new MappingSolrConverter(new SimpleSolrMappingContext());
        solrConverter.setCustomConversions(new CustomConversions(null));
        return solrConverter;
    }

    @Bean
    public SolrClientFactory solrClientFactory () throws Exception {
        return new MulticoreSolrClientFactory(solrClient());
    }

    @Bean
    public SolrClient solrClient() throws Exception {
        return new HttpSolrClient.Builder(solrHost).build();
    }

    @Bean
    public SolrOperations associationsTemplate() throws Exception {
        SolrTemplate solrTemplate = new SolrTemplate(solrClient());
        solrTemplate.setSolrConverter(solrConverter());
        return solrTemplate;
    }

}

Unfortunately, when I try to read an association from my Solr instance I got the following error:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [org.springframework.data.solr.core.geo.Point]

I don't understand why it is not able to find a converter if I have explicitly defined it in the solrTemplate() method.

This is my POM definition:

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-solr</artifactId>
        <version>2.1.4.RELEASE</version>
    </dependency>

Thank you for your help.

EDIT: I've also tried with different BUILD-RELEASEs but they are highly unstable and I've found a lot of errors using them.

Upvotes: 2

Views: 3869

Answers (1)

Andrea Ciapetti
Andrea Ciapetti

Reputation: 31

Alessandro, as you can see directly in the GeoConverters class on GitHub, the implemented converters are only for:

org.springframework.data.geo.Point

and not for:

org.springframework.data.solr.core.geo.Point

Simply use this class and you don't even need a custom converter for this. Spring Data for Solr will perform the conversion for you. I'm using a slightly patched version of the 3.0.0 M4, but I'm pretty sure this solution should apply seamlessly also to your case.

Upvotes: 2

Related Questions