找不到能够从类型[java.lang.String]转换为类型[org.springframework.data.solr.core.geo.Point]的转换器

找不到能够从类型[java.lang.String]转换为类型[org.springframework.data.solr.core.geo.Point]的转换器

问题描述:

我试图使用spring-data-solr来访问我的Solr实例通过我的Spring启动应用程序。我有以下的bean类:找不到能够从类型[java.lang.String]转换为类型[org.springframework.data.solr.core.geo.Point]的转换器

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

我创建了一个配置类,它看起来像下面的一个:

@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; 
    } 
} 

,以获得相关信息我已实现了以下库

@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; 
    } 

} 

不幸的是,当我尝试从我的Solr的情况下读取的关联,我得到了以下错误:

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] 

我不明白为什么它不能找到一个转换器,如果我已经明确地在solrTemplate()方法中定义它。

这是我的POM定义:

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

谢谢您的帮助。

编辑: 我也尝试过不同的BUILD-RELEASEs,但它们非常不稳定,我发现了很多使用它们的错误。

亚历山德罗,你可以在GitHub上的GeoConverters类直接看到,实现转换器只能用于:

org.springframework.data.geo.Point 

而不是为:

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

只需使用这个类,你不要甚至不需要为此定制转换器。 Spring Data for Solr将为您执行转换。 我使用的是3.0.0 M4的稍微修补版本,但我很肯定这个解决方案应该可以无缝应用到您的案例中。

+0

谢谢安德烈。我没有时间来解决这个问题。我有太多的Solr/Spring概念编码证明可以解决这个问题。太糟糕了,尽管solr特定的Point类被定义并暗示为用于Solr工作的正确Point。 –