java.lang.NoSuchFieldError:INSTANCE
尝试通过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
@Componentpublic 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
@Componentpublic class SomeClient {
private final CloseableHttpClient httpClient;
public SomeClient() {
this.httpClient = (httpClient == null ? HttpClients.createDefault() : httpClient);
}
}
AppContext.java
@Componentpublic 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解决了该问题。
以上是 java.lang.NoSuchFieldError:INSTANCE 的全部内容, 来源链接: utcz.com/qa/430819.html