我正在尝试使用基本的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
似乎已被“弃用”。我不知道究竟是什么意思,但有人可以告诉我问题是什么,是否有可能解决它?谢谢。
答案 0 :(得分:7)
HttpSolrClient有constructor接受HttpClient。未传递时,它会创建一个InternalClient,它是一个CloseableHttpClient。
因此,您可以创建一个默认客户端并按如下方式传递它。
SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
HttpSolrClient client = new HttpSolrClient(url, httpClient);
答案 1 :(得分:3)
如果不能重现问题,有点难以理解问题是什么。无论如何,似乎Solr方法返回的DefaultHttpClient
是而不是一个CloseableHttpClient
,这真的很奇怪,因为快速查看来源告诉我实际上{{1 }是Default***
的孙子。
然而,这个跟踪就是我们所拥有的:我猜你的项目对某些版本的Apache httpclient有一个(直接或间接)依赖,它与编译的Solr不兼容。您应该转储完整的依赖关系树,并确保只有一个版本。
答案 2 :(得分:0)
在classpath中更多版本的httpclient肯定存在问题。 我在SolrJ版本6.6.0中遇到了同样的问题,所以我切换到版本7.0.1并获得了另一个“版本”异常:
错误:INSTANCE
INFO mapreduce.Job: Task Id attempt_xzy, Status : FAILED
Error: INSTANCE
在纱线日志中:
ERROR [main] org.apache.hadoop.mapred.YarnChild:
Error running child : java.lang.NoSuchMethodError:
org.apache.solr.client.solrj.impl.CloudSolrClient$Builder.withHttpClient(Lorg/shaded/apache/http/client/HttpClient;)Lorg/apache/solr/client/solrj/impl/SolrClientBuilder;
如果您使用Maven,解决方案是使用shade plugin并制作这样的胖罐:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>${main.class.full.name}</Main-Class>
<Build-Number>1.0</Build-Number>
</manifestEntries>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>org.shaded.apache.http</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
备注:强>
1。 使集群类路径提供的所有其他依赖项都提供
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.1</version>
<scope>provided</scope>
</dependency>
如何查找版本问题:
yarn classpath
或find /usr/hdp/current -type f -name "*httpclient*"
你会看到这样的事情:
./hadoop/lib/httpclient-4.2.5.jar
./hadoop/lib/commons-httpclient-3.1.jar
./hadoop/lib/ranger-hdfs-plugin-impl/httpclient-4.5.2.jar
./ranger-hdfs-plugin/lib/ranger-hdfs-plugin-impl/httpclient-4.5.2.jar
./hadoop-yarn/lib/httpclient-4.2.5.jar
./hadoop-yarn/lib/commons-httpclient-3.1.jar
答案 3 :(得分:0)