我正在尝试使用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但它们非常不稳定,我发现使用它们时会出现很多错误。
答案 0 :(得分:1)
Alessandro,您可以直接在GitHub上的GeoConverters课程中看到,实现的转换器仅用于:
org.springframework.data.geo.Point
而不是:
org.springframework.data.solr.core.geo.Point
只需使用此类,您甚至不需要自定义转换器。 Solr的Spring Data将为您执行转换。 我使用的是3.0.0 M4的略微修补版本,但我很确定这个解决方案也应该无缝地适用于你的情况。