2017-06-29 186 views
2

我試圖使用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,但它們非常不穩定,我發現了很多使用它們的錯誤。

回答

1

亞歷山德羅,你可以在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。 –

相關問題