【发布时间】:2017-06-29 15:47:17
【问题描述】:
我正在尝试使用 spring-data-solr 以便通过我的 Spring 引导应用程序访问我的 Solr 实例。我有以下 bean 类:
@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;
}
}
为了访问相关信息,我实现了以下存储库:
public interface AssociationsRepository extends SolrCrudRepository<Association, String> {
}
我创建了一个配置类,如下所示:
@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-RELEASE,但它们非常不稳定,我发现使用它们时会出现很多错误。
【问题讨论】:
标签: spring-data-solr