尝试通过StormSubmitter提交结构时,我得到
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
我正在使用Spring。
我没有在Spout / Bolt构造函数中初始化HttpClient。相反,它是在prepare()通过螺栓方法从Spring Context中获取的类的构造函数中初始化的
代码的结构如下-
SomeBolt.java
@Component
public class SomeBolt extends BaseRichBolt {
private OutputCollector _collector;
private SomeClient someClient;
@Override
public void prepare(Map conf, TopologyContext context, OutputCollector collector) {
_collector = collector;
someClient = AppContext.getBean(SomeClient.class);
}
}
SomeClient.java
@Component
public class SomeClient {
private final CloseableHttpClient httpClient;
public SomeClient() {
this.httpClient = (httpClient == null ? HttpClients.createDefault() : httpClient);
}
}
AppContext.java
@Component
public class AppContext implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
AppContext.applicationContext = applicationContext;
}
public static <T> T getBean(Class<T> c) {
return applicationContext.getBean(c);
}
}
我遇到了类似的问题,在我的类路径中有两个包含相同类的jar,即httpcore-4.3和apache-httpcomponents-httpcore,我从类路径中删除了apache-httpcomponents-httpcore解决了该问题。
问题内容: 我将Apache的HttpClient组件用于以下简单程序,并且看到以下异常: 我在用 Httpclient-4.3.3.jar Httpcore-4.3.2.jar 有任何想法吗? 问题答案: 此代码有效…没有任何错误..如果您使用的是类似import,请检查软件包。