加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – org.testng.TestNGException尝试访问PoolingHttpClientC

发布时间:2020-12-15 03:08:15 所属栏目:Java 来源:网络整理
导读:所以我最近在尝试使用IDE运行现有测试套件时开始面临TestNGException.最近我的意思是更新intelliJ和依赖项以尝试处理最新版本.失败的代码和堆栈跟踪如下 – 代码使用 ITests.java – public class ITests extends BaseTest { private final Action action =
所以我最近在尝试使用IDE运行现有测试套件时开始面临TestNGException.最近我的意思是更新intelliJ和依赖项以尝试处理最新版本.失败的代码和堆栈跟踪如下 –

代码使用

ITests.java –

public class ITests extends BaseTest {
    private final Action action = new Action();
}

BaseTest(只是为了分享语法) –

public class BaseTest {
    // where in this class does not use any instance of Http
}

Action.java –

public class Action {
    private final Http http = Http.getInstance();
}

Http.java –

public class Http {

    private static final Http INSTANCE = new Http(); //line 36

    public static Http getInstance() {
        return INSTANCE;
    }

    private Http() {
        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); //line 43
        connectionManager.setMaxTotal(100);
        connectionManager.setDefaultMaxPerRoute(100);
        RequestConfig defaultRequestConfig = RequestConfig.custom()
                .setSocketTimeout(60000)
                .setConnectTimeout(60000)
                .setConnectionRequestTimeout(60000)
                .build();
        this.client = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig)
                .setConnectionManager(connectionManager).build();
    }
}

Maven依赖 –

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.2</version>
</dependency>

堆栈跟踪 –

06005

注意 – 我们的项目基于maven,所以当我使用maven exec执行测试时:java执行正常.

请询问所需的任何其他信息.

编辑1 –

正如@hunter所要求的,调试以从加载的位置获取Cpool的确切路径.评估 –

Class.forName("org.apache.http.impl.conn.CPool").getResource??("CPool.class")

结果 –

file:/Users/xyz/.m2/repository/org/apache/httpcomponents/httpclient/4.5.2/httpclient-4.5.2.jar!/org/apache/http/impl/conn/CPool.class

编辑2 –

mvn依赖:树[与httpcomponents最相关] –

— maven-dependency-plugin:2.8:树

com.package:core:jar:1.1.3

+- org.apache.httpcomponents:httpclient:jar:4.5.2:compile |  +- org.apache.httpcomponents:httpcore:jar:4.4.4:compile |  +- commons-logging:commons-logging:jar:1.2:compile |  - commons-codec:commons-codec:jar:1.9:compile
+- com.google.collections:google-collections:jar:1.0:compile
+- commons-io:commons-io:jar:2.5:compile
+- org.apache.commons:commons-lang3:jar:3.4:compile
+- org.json:json:jar:20160810:compile - org.testng:testng:jar:6.9.9:compile

com.package:test:jar:1.1.3

+- mysql:mysql-connector-java:jar:6.0.3:compile
+- org.apache.httpcomponents:httpclient:jar:4.5.2:compile |  +- org.apache.httpcomponents:httpcore:jar:4.4.4:compile |  +- commons-logging:commons-logging:jar:1.2:compile |  - commons-codec:commons-codec:jar:1.9:compile
+- com.package:mobile:jar:3.6.2:compile |  +- com.pkg.serviceproxy:http-handler:jar:1.7.41:compile |  |  +- org.apache.httpcomponents:httpcore-nio:jar:4.3:compile |  +- com.pkg:bullseye-model:jar:1.2.0:compile |  |  +- com.codahale.metrics:metrics-httpclient:jar:3.0.2:compile |  +- kpg:pz-api:jar:0.2.38:compile |  |  - com.mashape.unirest:unirest-java:jar:1.4.7:compile |  |     +- org.apache.httpcomponents:httpasyncclient:jar:4.0.2:compile |  |     - org.apache.httpcomponents:httpmime:jar:4.3.6:compile
+- com.package:core:jar:1.1.3:compile

com.package:driver:jar:1.1.3

- com.package:test:jar:1.1.3:compile

编辑3 –
intelliJ IDEA – 15.0.3 [社区] – 2016年1月19日更新

编辑4 –

向IntelliJ倾斜更多,在使用testng.xml运行测试后共享日志 – >右键单击 – >跑

> objc[21590]: Class JavaLaunchHelper is implemented in both
> /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/bin/java
> and
> /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home/jre/lib/libinstrument.dylib.
> One of the two will be used. Which one is undefined.
> [AppClassLoader@14dad5dc] error can't determine annotations of missing
> type javax.cache.annotation.CachePut when weaving type
> com.intellij.rt.execution.application.AppMain when weaving classes 
> when weaving   [Xlint:cantFindType] [AppClassLoader@14dad5dc] error
> can't determine annotations of missing type
> javax.cache.annotation.CacheResult when weaving type
> com.intellij.rt.execution.application.AppMain when weaving classes 
> when weaving   [Xlint:cantFindType] [AppClassLoader@14dad5dc] error
> can't determine annotations of missing type
> javax.cache.annotation.CacheRemove when weaving type
> com.intellij.rt.execution.application.AppMain when weaving classes 
> when weaving   [Xlint:cantFindType] [AppClassLoader@14dad5dc] error
> can't determine annotations of missing type
> javax.cache.annotation.CacheRemoveAll when weaving type
> com.intellij.rt.execution.application.AppMain when weaving classes 
> when weaving   [Xlint:cantFindType]

解决方法

在IDEA,Maven项目选项卡中,单击Show dependencies按钮(它将显示一个图表),然后在该图中按Ctrl F并键入httpcore并检查版本.如果它显示的版本低于4.4,您可以分析依赖关系的解析方式.基于此,您可以调整pom以纠正依赖关系.由于它在命令行中使用mvn,因此可能是该IDEA通过其maven插件解析maven依赖项的错误行为.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读