2

I'm using Spring Data Solr to implement the search module in my project. To enable multicore support, I simply instantiate a HttpSolrServer and then declare a java-based Spring configuration class with @EnableSolrRepositores(multicoreSupport=true). Everything works perfectly, until when I try to write integration test for Solr related codes and schema.

I want to use EmbeddedSolrServer for testing so that the tests can run without depending on an external Solr server, but I can't find a way to configure correctly. Please advise.

tashuhka
  • 5,028
  • 4
  • 45
  • 64
Ziju Feng
  • 327
  • 1
  • 4
  • 13

1 Answers1

5

This can at this time not be done directly due to DATASOLR-203.

Once the issue mentioned above is resolved you can do it as follows:

@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);
  }
}
Christoph Strobl
  • 6,491
  • 25
  • 33
  • Thanks for the information. I'll give 1.2.5 a try once it is out. – Ziju Feng Sep 17 '14 at 12:02
  • 1
    @NikhilSahu EmbeddedSolrServer is not depracated i just tested it with solr-core-5.4.1 – kozla13 Feb 17 '16 at 08:22
  • spring-data-solr uses solrj4. Explicitly mentioning later versions of solrj dependency will show SolrServer as deprecated and now inherits from SolrClient. All functions have been moved to SolrClient. – Nikhil Sahu Feb 17 '16 at 09:09
  • SD-Solr 2.0.0.M1 moved to Solr 5. `EmbeddedSolrServer` extends `SolrClient` and can be created via the [`EmbeddedSolrServerFactory`](https://github.com/spring-projects/spring-data-solr/blob/master/src/main/java/org/springframework/data/solr/server/support/EmbeddedSolrServerFactory.java) – Christoph Strobl Feb 17 '16 at 09:30