问题概述
根据要求对Solr服务进行升级,经过全面改操后,启动项目时,单元测试一直报错,测试无法通过,项目启动不起来,异常:“ Caused by: java.lang.ClassNotFoundException: org.apache.http.message.TokenParser ”,
部分截图如下:
具体异常信息:
java.lang.NoClassDefFoundError: org/apache/http/message/TokenParser
at org.apache.http.client.utils.URLEncodedUtils.parse(URLEncodedUtils.java:288)
at org.apache.http.client.utils.URLEncodedUtils.parse(URLEncodedUtils.java:249)
at org.apache.http.client.utils.URIBuilder.parseQuery(URIBuilder.java:111)
at org.apache.http.client.utils.URIBuilder.digestURI(URIBuilder.java:199)
at org.apache.http.client.utils.URIBuilder.<init>(URIBuilder.java:91)
at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:206)
at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:347)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:471)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:448)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:210)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:206)
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:91)
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
at com.huazai.b2c.aiyou.test.solrj.TSolrjClient.queryDocumentById(TSolrjClient.java:232)
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:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: java.lang.ClassNotFoundException: org.apache.http.message.TokenParser
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 41 more
解决办法
经过博主的各种骚操作,最终把这个坑填好了,其天坑过程就不过多的叨叨了,
两种解决办法:
1、将solr版本降到4.x
solr4.x使用的 HttpSolrServer,SolrServer
solr5.x以后升级,改为了 HttpSolrClient,SolrClient
就不贴源码了,点到为止,感兴趣的可以去一探究竟,一般没有必要浪费去看这个的,博主看只是为了解决这个问题。
2、排除httpclient相关的两个依赖包:
<!-- solrj 客户端 -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>4.10.4</version>
<exclusions>
<exclusion>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
<exclusion>
<artifactId>httpcore</artifactId>
<groupId>org.apache.httpcomponents</groupId>
</exclusion>
</exclusions>
</dependency>
有人提意见,将solrj升级到5.x以后或最新版本,如果一样是老系统,博主不见升级,牵一发则动全身,会出现各种版本不兼容(因为博主试过,升级后,出现各种不兼容的情况,这个坑填好,又出现另一个坑,让人感觉有永远填不完的坑,经过一顿猛如虎的操作后,几乎到了崩溃边缘,然后果断回滚代码,关掉IDE,长长的深吸了口气,终于解决了,结束!!!)
解决问题后,再次测试,通了:
好了,关于 Caused by: java.lang.ClassNotFoundException: org.apache.http.message.TokenParser 异常的解决办法 就写到这儿了,如果还有什么疑问或遇到什么问题欢迎扫码提问,也可以给我留言哦,我会一一详细的解答的。
歇后语:“ 共同学习,共同进步 ”,也希望大家多多关注CSND的IT社区。
作 者: | 华 仔 |
联系作者: | who.seek.me@java98k.vip |
来 源: | CSDN (Chinese Software Developer Network) |
原 文: | https://blog.csdn.net/Hello_World_QWP/article/details/98340187 |
版权声明: | 本文为博主原创文章,请在转载时务必注明博文出处! |