公司项目中已经有了自己封装的HttpUtil工具类了,新来的同事没仔细看,又自己封装了一个httpclient,在这个过程中,还碰见了一个版本号不对应的问题,导致报了一个错误:“java: 无法访问org.apache.http.annotation.NotThreadSafe,找不到org.apache.http.annotation.NotThreadSafe的类文件”。
经检查,发现是因为他引入的两个httpcomponents的包有问题,他在pom.xml引入的两个依赖如下:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.6</version>
</dependency>
一个httpclient,一个httpcore,看起来也没啥不对,但问题就出在了httpcore的版本号上,httpclient4.5.2和httpcore4.4.6不太相配,将httpcore降级到4.4.4之后,问题得到解决!
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<!--httpclient 4.5.2 与 httpcore 4.4.4 更配哦-->
<version>4.4.4</version>
</dependency>
评论