Solr7正确的调用SolrClient姿势

好多文章习惯这么调用SolrClient:

final String solrUrl = "http://localhost:8983/solr/solr_core";
HttpSolrClient client = new HttpSolrClient.Builder(solrUrl)
        .withConnectionTimeout(10000)
        .withSocketTimeout(60000)
        .build();
//查询
//.............
final QueryResponse response = client.query(queryParams);
//新增
//.............
client.add(document);
client.commit();         

这种方式在main方法测试中没什么问题,如果通过SpringBoot进行客户端注入调用就会报错:org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/new_core: Expected mime type application/octet-stream but got text/html
通过查询官方案例,正确的调用姿势如下:

final String solrUrl = "http://localhost:8983/solr/";
final String solrCore = "solr_core";
HttpSolrClient client = new HttpSolrClient.Builder(solrUrl)
        .withConnectionTimeout(10000)
        .withSocketTimeout(60000)
        .build();
//查询
//.............
final QueryResponse response = client.query(solrCore,queryParams);
//新增
//.............
client.add(solrCore,document);
client.commit(solrCore);         
只有把命运掌握在自己手中,从今天起开始努力,即使暂时看不到希望,也要相信自己。因为比你牛几倍的人,依然在努力。
原文地址:https://www.cnblogs.com/freesky168/p/14358206.html