您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Spring Data Solr的多个核心和存储库

Spring Data Solr的多个核心和存储库

以为我会分享:最近我们花大量时间配置多个内核。我们是用Java而不是xml做的。

作为spring @configuration的一部分,添加以下内容

@Bean(name="solrCore1Template")
public SolrTemplate solrCore1Template() throws Exception {
    EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(getCoreContainer(), "core1");
    return new SolrTemplate(embeddedSolrServer);
}

@Bean(name="solrCore2Template")
public SolrTemplate solrCore2Template() throws Exception {   
    EmbeddedSolrServer embeddedSolrServer = new EmbeddedSolrServer(getCoreContainer(), "core2");
    return new SolrTemplate(embeddedSolrServer);
}

@Bean
@Scope
public CoreContainer getCoreContainer() throws FileNotFoundException{
    String dir = <path_to_solr_home>;
    System.setProperty("solr.solr.home", dir);
    CoreContainer.Initializer initializer = new CoreContainer.Initializer();
    return initializer.initialize();
}

并且要使用每个模板,请在服务类中使用以下内容

@Resource
private SolrTemplate solrCore1Template;

可以使用以下代码将嵌入式服务器替换为HTTP。

HttpSolrServer httpSolrServer = new HttpSolrServer(getSolrURL());
return new SolrTemplate(httpSolrServer, "core1");

希望这可以帮助。我知道这是一个很晚才回答的问题。

Solr 2022/1/1 18:22:35 有465人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶