如何配置 Spring Data Solr with Repositories for multiple cores
How to configure Spring Data Solr with Repositories for multiple cores
是否有关于使用支持多核的存储库通过 solr 设置 spring 数据的详细和完整的解释?
需要用于 spring-data-solr 的唯一依赖项是
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
它下载 solrj 依赖项,这不能被更高版本的 solrj 覆盖。
此外,最好使用 HttpSolrServer 而不是我们将要使用的 EmbeddedSolrServer。
配置 class 应该如下所示:
@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
}
一旦指定的 url 上的 solr 运行 并且它具有根据 pojo 的字段,您就完成了。
是否有关于使用支持多核的存储库通过 solr 设置 spring 数据的详细和完整的解释?
需要用于 spring-data-solr 的唯一依赖项是
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.5.2.RELEASE</version>
</dependency>
它下载 solrj 依赖项,这不能被更高版本的 solrj 覆盖。 此外,最好使用 HttpSolrServer 而不是我们将要使用的 EmbeddedSolrServer。
配置 class 应该如下所示:
@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
}
一旦指定的 url 上的 solr 运行 并且它具有根据 pojo 的字段,您就完成了。