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);
    }
}

答案 1

这可能是一个依赖关系问题。

这是一个非常不清楚的错误消息,但我在这里发现了类似的东西:Hibernate NoSuchFieldError INSTANCE,但只与Struts 1?


答案 2

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


推荐