一尘不染

java.lang.NoSuchFieldError:INSTANCE

spring

尝试通过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);
    }
}

阅读 941

收藏
2020-04-15

共1个答案

一尘不染

我遇到了类似的问题,在我的类路径中有两个包含相同类的jar,即httpcore-4.3和apache-httpcomponents-httpcore,我从类路径中删除了apache-httpcomponents-httpcore解决了该问题。

2020-04-15