是否有使用具有多核支持的存储库的solr设置弹簧数据的详细而完整的说明?
答案 0 :(得分:4)
需要用于spring-data-solr的唯一依赖是
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
它会下载solrj依赖项,不能用更高版本的solrj 覆盖它。 另外,最好在EmbeddedSolrServer上使用HttpSolrServer,这是我们将要使用的。
Configuration类应如下所示:
@Configuration
@EnableSolrRepositories(value = "com.package.",multicoreSupport = true)
public class SolrConfig
{
@Bean
public SolrServer solrServer() throws Exception
{
HttpSolrServerFactoryBean f = new HttpSolrServerFactoryBean();
f.setUrl("http://localhost:8983/solr");
f.afterPropertiesSet();
return f.getSolrServer();
}
@Bean
public SolrTemplate solrTemplate(SolrServer solrServer) throws Exception
{
return new SolrTemplate(solrServer());
}
}
文档实体应包含有关其所属核心的信息
@SolrDocument(solrCoreName = "core1")
public class Document1
{
@Id
@Field
private String id;
/**other attributes**/
}
另一份文件应为
@SolrDocument(solrCoreName = "core2")
public class Document2
{
@Id
@Field
private String id;
/**other attributes**/
}
现在最好的部分是你已经完成了。简单地以简单的方式设置存储库就可以了解
public interface SolrCore1Repository extends SolrCrudRepository<Document1,String>
{
// optional code
}
另一个回购就好像
public interface SolrCore2Repository extends SolrCrudRepository<Document2,String>
{
// optional code
}
一旦solr在指定的url上运行并且它具有根据pojo的字段,你就完成了。