如何使用EmbeddedSolrServer和多核支持设置Spring Data Solr



我正在使用Spring Data Solr在我的项目中实现搜索模块。为了启用多核支持,我只需实例化一个HttpSolrServer,然后用@EnableSolrRepositores(multicoreSupport=true)声明一个基于java的Spring配置类。一切都很完美,直到我尝试为Solr相关的代码和模式编写集成测试。

我想使用EmbeddedSolrServer进行测试,这样测试就可以在不依赖外部Solr服务器的情况下运行,但我找不到正确配置的方法。请告知。

由于DATASOLR-203,目前无法直接执行此操作。

一旦上述问题得到解决,您可以按照以下方式进行操作:

@Configuration
@EnableSolrRepositories(multicoreSupport = true)
static class SolrConfiguration {
  @Bean
  SolrServer solrServer() throws FileNotFoundException {
    String solrHome = ResourceUtils.getURL("classpath:your/path/here").getPath();
    CoreContainer container = CoreContainer.createAndLoad(solrHome, new File(solrHome + "/solr.xml"));
    return new EmbeddedSolrServer(container, null);
  }
}

最新更新