org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setValidateAfterInactivity(I)V 错误的解决办法
问题概述
根据要求对Solr进行升级,各个配置升级改操到位后,启动项目时,单元测试模块不通过,导致项目一直无法启动,错误信
息:“ org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setValidateAfterInactivity(I)V ”
升级的服务版本如下图所示:
部分截图如下:
控制台打印:
2019-08-02 10:32:53,668 [main] [org.apache.solr.client.solrj.impl.HttpClientUtil]-[DEBUG] Creating new http client, config:followRedirects=false&allowCompression=false
具体的错误信息如下:
java.lang.NoSuchMethodError: org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setValidateAfterInactivity(I)V at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:279) at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:330) at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:268) at org.apache.solr.client.solrj.impl.HttpClientUtil.createClient(HttpClientUtil.java:255) at org.apache.solr.client.solrj.impl.HttpSolrClient.<init>(HttpSolrClient.java:201) at org.apache.solr.client.solrj.impl.HttpSolrClient$Builder.build(HttpSolrClient.java:943) at com.huazai.b2c.aiyou.test.solrj.TSolrjClient.addDocument(TSolrjClient.java:37) 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)
解决办法
经过了几天的摸排,因为这个问题有点独特,网上基本上没有看到参考资料,然后就是从系统日志、到官方文档,还是没有头绪,最后通过控制台输出的日志,初步判定,为 HttpClientUtiil 包不兼容的问题,为什么要作出这样的判定呢,因为一般对老版本的系统进行升级改操的时候,最让人头痛的一个问题就是面临各种的不兼容的问题(需要根据个人经验来判定);
从异常信息的第二行看,随初步判断为 HttpClientUtil 包不兼容的问题,将HttpClientUtil和SolrJ进行对称升级操作:
<dependency> <groupId>org.apache.solr</groupId> <artifactId>solr-solrj</artifactId> <version>8.2.0</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.9</version> </dependency>
后来从其依赖体系关系中摸查了哈,果不其然为 HttpClient 包的兼容问题导致的,如下图:
解决后再次请求:
好了,关于 org.apache.http.impl.conn.PoolingHttpClientConnectionManager.setValidateAfterInactivity(I)V 错误的解决办法 就