gpt4 book ai didi

java - 扩展 HttpEntityEnshingRequestBase 时出错

转载 作者:行者123 更新时间:2023-12-02 01:44:16 24 4
gpt4 key购买 nike

我正在尝试创建一个自定义 GET 请求,该请求可以将 body 与第三部分 API 一起使用。我为此编写了以下代码:

public class HttpGetWithEntity extends HttpEntityEnclosingRequestBase {

public static final String METHOD_NAME = "GET";

public HttpGetWithEntity() {
}

public HttpGetWithEntity(URI uri) {
this.setURI(uri);
}

public HttpGetWithEntity(String uri) {
this.setURI(URI.create(uri));
}

@Override
public String getMethod() {
return METHOD_NAME;
}
}

问题是 HttpEntityEnlookingRequestBase 类使用以下注释:

@NotThreadSafe
public abstract class HttpEntityEnclosingRequestBase extends HttpRequestBase implements HttpEntityEnclosingRequest {

此扩展已从 org.apache.http.annotation 中删除,因此在编译我的应用程序时,我收到以下错误:

cannot access org.apache.http.annotation.NotThreadSafe
class file for org.apache.http.annotation.NotThreadSafe not found

我怎样才能避免这种情况,因为我无法从谷歌搜索中找到一些东西,也无法阅读扩展HttpEntityEnlookingRequestBase的其他代码。还有其他方法可以通过 GET 请求发送正文吗?

最佳答案

org.apache.httpcomponents:httpcore 依赖项版本更新到 4.4.11 或更高版本后,出现

@ThreadSafe class not find 编译错误。此 httpcore 版本附带:

Class org.apache.http.annotation.Immutable removed
Class org.apache.http.annotation.NotThreadSafe removed
Class org.apache.http.annotation.ThreadSafe removed

而不是这些删除的类 org.apache.http.annotation.Contract 注释和 org.apache.http.annotation.ThreadingBehavior enum已介绍。

所以现在您应该将 @ThreadSafe 事件重构为 org.apache.http.annotation.Contract 注释并传递 ThreadingBehavior 枚举值 SAFE 来指定线程安全的行为契约

@Contract(threading = ThreadingBehavior.SAFE)

@NotThreadSafe transforms to ThreadingBehavior.UNSAFE

@Immutable to ThreadingBehavior.IMMUTABLE or IMMUTABLE_CONDITIONAL

关于java - 扩展 HttpEntityEnshingRequestBase 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57472392/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com