java – Solr错误的返回类型错误

我正在尝试使用基本的Solr教程,我收到一个我以前既没有见过的错误也无法找到有关在线的详细信息.

我的代码是:

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.common.SolrInputDocument;

import java.io.IOException;

public class SolrjPopulator {
  public static void main(String[] args) throws IOException, SolrServerException {
    HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr");
    for(int i=0;i<1000;++i) {
      SolrInputDocument doc = new SolrInputDocument();
      doc.addField("cat", "book");
      doc.addField("id", "book-" + i);
      doc.addField("name", "The Legend of the Hobbit part " + i);
      server.add(doc);
      if(i%100==0) server.commit();  // periodically flush
    }
    server.commit(); 
  }
}

我得到的控制台错误是:

Exception in thread "main" java.lang.VerifyError: Bad return type
Exception Details:
  Location:
    org/apache/solr/client/solrj/impl/HttpClientUtil.createClient(Lorg/apache/solr/common/params/SolrParams;Lorg/apache/http/conn/ClientConnectionManager;)Lorg/apache/http/impl/client/CloseableHttpClient; @62: areturn
  Reason:
    Type 'org/apache/http/impl/client/DefaultHttpClient' (current frame, stack[0]) is not assignable to 'org/apache/http/impl/client/CloseableHttpClient' (from method signature)
  Current Frame:
    bci: @62
    flags: { }
    locals: { 'org/apache/solr/common/params/SolrParams', 'org/apache/http/conn/ClientConnectionManager', 'org/apache/solr/common/params/ModifiableSolrParams', 'org/apache/http/impl/client/DefaultHttpClient' }
    stack: { 'org/apache/http/impl/client/DefaultHttpClient' }
  Bytecode:
    0x0000000: bb00 0359 2ab7 0004 4db2 0005 b900 0601
    0x0000010: 0099 001e b200 05bb 0007 59b7 0008 1209
    0x0000020: b600 0a2c b600 0bb6 000c b900 0d02 00bb
    0x0000030: 0011 592b b700 124e 2d2c b800 102d b0 
  Stackmap Table:
    append_frame(@47,Object[#127])

            at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:186)
            at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:159)
            at org.apache.solr.client.solrj.impl.HttpSolrServer.<init>(HttpSolrServer.java:30)
            at com.coba.efx.news.server.SolrPopulator.main(SolrPopulator.java:14)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:483)
            at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)

Process finished with exit code 1

此外,类HttpSolrServer似乎被“弃用”.我不知道究竟是什么意思,但有人可以告诉我问题是什么,是否有可能解决它?谢谢.

最佳答案
HttpSolrClient有一个接受HttpClient的constructor.未传递时,它会创建一个InternalClient,它是一个CloseableHttpClient.

因此,您可以创建一个默认客户端并按如下方式传递它.

SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
HttpSolrClient client = new HttpSolrClient(url, httpClient);

转载注明原文:java – Solr错误的返回类型错误 - 代码日志