当前位置:   article > 正文

Caused by: java.lang.ClassNotFoundException: org.apache.http.message.TokenParser 异常的解决办法

caused by: java.lang.classnotfoundexception: org.apache.http.impl.client.htt

问题概述

根据要求对Solr服务进行升级,经过全面改操后,启动项目时,单元测试一直报错,测试无法通过,项目启动不起来,异常:“ Caused by: java.lang.ClassNotFoundException: org.apache.http.message.TokenParser ”,

部分截图如下:

具体异常信息:

  1. java.lang.NoClassDefFoundError: org/apache/http/message/TokenParser
  2. at org.apache.http.client.utils.URLEncodedUtils.parse(URLEncodedUtils.java:288)
  3. at org.apache.http.client.utils.URLEncodedUtils.parse(URLEncodedUtils.java:249)
  4. at org.apache.http.client.utils.URIBuilder.parseQuery(URIBuilder.java:111)
  5. at org.apache.http.client.utils.URIBuilder.digestURI(URIBuilder.java:199)
  6. at org.apache.http.client.utils.URIBuilder.<init>(URIBuilder.java:91)
  7. at org.apache.http.client.utils.URIUtils.rewriteURI(URIUtils.java:206)
  8. at org.apache.http.impl.client.DefaultRequestDirector.rewriteRequestURI(DefaultRequestDirector.java:347)
  9. at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:471)
  10. at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
  11. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
  12. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)
  13. at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
  14. at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:448)
  15. at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:210)
  16. at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:206)
  17. at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:91)
  18. at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
  19. at com.huazai.b2c.aiyou.test.solrj.TSolrjClient.queryDocumentById(TSolrjClient.java:232)
  20. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  21. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  22. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  23. at java.lang.reflect.Method.invoke(Method.java:497)
  24. at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  25. at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  26. at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  27. at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  28. at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  29. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  30. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  31. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  32. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  33. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  34. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  35. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  36. at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  37. at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
  38. at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  39. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
  40. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
  41. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
  42. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
  43. Caused by: java.lang.ClassNotFoundException: org.apache.http.message.TokenParser
  44. at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  45. at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  46. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  47. at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  48. ... 41 more

 

解决办法

经过博主的各种骚操作,最终把这个坑填好了,其天坑过程就不过多的叨叨了,

两种解决办法:

1、将solr版本降到4.x

solr4.x使用的 HttpSolrServer,SolrServer

solr5.x以后升级,改为了 HttpSolrClient,SolrClient

就不贴源码了,点到为止,感兴趣的可以去一探究竟,一般没有必要浪费去看这个的,博主看只是为了解决这个问题。

 

2、排除httpclient相关的两个依赖包:

  1. <!-- solrj 客户端 -->
  2. <dependency>
  3. <groupId>org.apache.solr</groupId>
  4. <artifactId>solr-solrj</artifactId>
  5. <version>4.10.4</version>
  6. <exclusions>
  7. <exclusion>
  8. <artifactId>httpclient</artifactId>
  9. <groupId>org.apache.httpcomponents</groupId>
  10. </exclusion>
  11. <exclusion>
  12. <artifactId>httpcore</artifactId>
  13. <groupId>org.apache.httpcomponents</groupId>
  14. </exclusion>
  15. </exclusions>
  16. </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
版权声明:本文为博主原创文章,请在转载时务必注明博文出处!
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/124490
推荐阅读
相关标签
  

闽ICP备14008679号