java - 扩展 HttpEntityEnclosureRequestBase 时出错
问题描述
我正在尝试制作一个自定义 GET 请求,该请求可以body
用于第 3 部分 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;
}
}
问题是HttpEntityEnclosingRequestBase
类使用以下注释:
@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
我怎样才能避免这种情况,因为我无法从谷歌搜索中找到一些东西并阅读一些其他正在扩展的代码HttpEntityEnclosingRequestBase
。还有其他方法可以通过 GET 请求发送正文吗?
解决方案
@ThreadSafe
org.apache.httpcomponents:httpcore
将您的依赖版本更新到4.4.11
或更高版本后,会发生找不到类编译错误。此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
推荐阅读
- html - 如何直接制表到子元素并忽略父元素
- android-studio - Flutter:任务“:app:transformClassesAndResourcesWithProguardForRelease”执行失败
- c - 什么可能是 C 中 SystemVerilog 中 casex 语句的等效方法
- idempiere - 尝试在 Idempiere 中导入 web 服务时无法在 packIn 对话框中看到 ZIP FileType
- python - 文本脱离 figsize plot.bar
- azure - 该节点有条件:[DiskPressure] 导致 azure/aks 中的 k8s 中的 pod 驱逐
- c++ - 除了概念之外,C++20 中还有其他 void_t 替代品吗?
- kotlin - 如何动态创建另一个类属性类型的列表(或任何其他集合)?
- swift - removeFromSuperView() 删除其所有子视图
- api - 列出过去一年的 Jenkins 工作构建详细信息以及触发构建的用户