java.lang.NoSuchFieldError: INSTANCE
2022-09-01 16:02:15
当尝试通过 StormSubmitter 提交我的拓扑时,我得到 -
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
我正在使用春天。
我没有在Spout/Bolt Constructor中初始化HttpClient。相反,它在一个类的构造函数中初始化,该类正在以螺栓方法从Spring Context中获取prepare()
代码结构如下 -
某博尔特.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);
}
}
有些客户.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);
}
}