title: Configure Spring Data Solr with multiple cores
body: <p>I'm having issues upgrading my solr configuration from 1.5.4 to 3.0.0.M4 (along with a Spring Boot update to 2.0.0.M2).</p>
  
  <p>Previous config file (spring-data-solr 1.5.4.RELEASE):</p>
  
  <pre><code>@Configuration
  @EnableSolrRepositories(value = "com.bar.foo.repository.solr", multicoreSupport = true)
  public class SolrConfiguration implements EnvironmentAware{
  
      private RelaxedPropertyResolver propertyResolver;
      private Environment             environment;
  
      @Override
      public void setEnvironment(Environment environment) {
          this.environment = environment;
          this.propertyResolver = new RelaxedPropertyResolver(environment, "spring.data.solr.");
      }
  
      @Bean
      public SolrServer solrServer() {
          String solrHost = propertyResolver.getProperty("host");
          return new HttpSolrServer(solrHost);
      }
  
  
      @Bean(name = "core1SolrTemplate")
      public SolrOperations core1SolrTemplate() {
          HttpSolrServer httpSolrServer = new HttpSolrServer(propertyResolver.getProperty("host"));
          return new SolrTemplate(httpSolrServer, "Core1");
      }
  
      @Bean(name = "core2SolrTemplate")
      public SolrOperations core2SolrTemplate() {
          HttpSolrServer httpSolrServer = new HttpSolrServer(propertyResolver.getProperty("host"));
          return new SolrTemplate(httpSolrServer, "Core2");
      }
      ...
  }
  </code></pre>
  
  <p>We are then using these solrtemplate in the code as </p>
  
  <pre><code>@Resource SolrTemplate core1SolrTemplate;
  @Resource SolrTemplate core2SolrTemplate;
  </code></pre>
  
  <p>Trying to update, I see that HttpSolrServer is no longer available, and we should use SolrClient, but with the removal of multicoreSupport and the ability to declare the template's core I don't get how to have a template per core (or a single one able to detect which core to query ?)</p>
  
  <p>Here's my current non-working config :</p>
  
  <pre><code>@Configuration
  @EnableSolrRepositories(value = "com.bar.foo.repository.solr")
  public class SolrConfiguration {
  
      @Inject
      private Environment             environment;
  
      @Bean
      public SolrClient solrClient() {
          return new HttpSolrClient.Builder(environment.getProperty("spring.data.solr.host")).build();
      }
  
      @Bean
      public SolrTemplate solrTemplate() {
          return new SolrTemplate(solrClient());
      }
  
  }
  </code></pre>
  
  <p>Our Pojos are configured as :</p>
  
  <pre><code>@SolrDocument(solrCoreName = "Core1")
  public class Foo{
      @Id
      private String                     id;
  
      ...
  }
  </code></pre>
  
  <p>and the call throwing the error</p>
  
  <pre><code>core1SolrTemplate.queryForPage(simpleQuery, Foo.class)
  </code></pre>
  
  <p>"Caused by: org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at <a href="http://192.168.99.100:8983/solr" rel="nofollow noreferrer">http://192.168.99.100:8983/solr</a>: Expected mime type application/octet-stream but got text/html. "</p>
  
  <p>It looks like the solrtemplate is only calling the baseurl without selecting any core.</p>
  
  <p>I also tried creating multiple SolrTemplate as before and passing a parameter to the solrClient() to construct a specific url per core but was unsuccessful to make it work (I had errors where the 2nd template was apparently using the first solrtemplate bean, pointing to the wrong core).</p>
  
  <p>How should I configure Solr to be able to query multiple cores ? </p>
  
  <p>Current (2.1.4) solr doc :
  <a href="http://docs.spring.io/spring-data/data-solr/docs/current/reference/html/#solr.multicore" rel="nofollow noreferrer">http://docs.spring.io/spring-data/data-solr/docs/current/reference/html/#solr.multicore</a> </p>
  
  <p>Multicore is not described in the 3.0.0.M4 doc :
  <a href="http://docs.spring.io/spring-data/data-solr/docs/3.0.0.M4/reference/html/#solr.multicore" rel="nofollow noreferrer">http://docs.spring.io/spring-data/data-solr/docs/3.0.0.M4/reference/html/#solr.multicore</a> </p>