java.lang.NoSuchFieldError: INSTANCE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21622885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.NoSuchFieldError: INSTANCE
提问by Harsh Moorjani
When trying to submit my topology through StormSubmitter, I am getting -
当尝试通过 StormSubmitter 提交我的拓扑时,我得到 -
Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
I am using Spring.
我正在使用弹簧。
I am not initializing HttpClient in Spout/Bolt Constructor. Instead its initialized in constructor of a class that is being fetched from Spring Context in prepare()
method of bolt
我没有在 Spout/Bolt 构造函数中初始化 HttpClient。相反,它在一个类的构造函数中初始化,该类的构造函数是在 Boltprepare()
方法中从 Spring Context 获取的
Code is structured as follows -
代码结构如下 -
SomeBolt.java
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
客户端.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);
}
}
采纳答案by K.C.
This is probably a dependency issue.
这可能是一个依赖问题。
It's a very unclear error message but I found something similar here: Hibernate NoSuchFieldError INSTANCE but only with Struts 1?
这是一个非常不清楚的错误消息,但我在这里发现了类似的内容: Hibernate NoSuchFieldError INSTANCE but only with Struts 1?
回答by lockwobr
Harsh is right its in the storm class path.
苛刻是正确的风暴类路径。
So what I did to make this work was remove the httpclient and httpcore that comes with storm and replaced them with newer version 4.3.3 and 4.3.2 respectively. This changes the classpath the works/nimbus/supervisor uses to start. You can run storm classpath and it print the class path out.
所以我所做的就是删除storm自带的httpclient和httpcore,分别用更新的4.3.3和4.3.2版本替换它们。这会更改works/nimbus/supervisor 用来启动的类路径。您可以运行 Storm classpath 并打印出类路径。
[nimbus ~]$ storm classpath
...../storm-0.8.2/lib/httpclient-4.3.3.jar:..../storm-0.8.2/lib/httpcore-4.3.2.jar.....
I am not sure this is a very good work around, I am not sure what part of storm uses this jar.
我不确定这是一个很好的解决方法,我不确定 Storm 的哪一部分使用了这个 jar。
if you look at the python stormcode you see that it will put all jars in the storm root and storm/lib
如果你查看 python Storm代码,你会发现它会将所有 jars 放在 Storm 根和 Storm/lib 中
def get_classpath(extrajars):
ret = get_jars_full(STORM_DIR)
ret.extend(get_jars_full(STORM_DIR + "/lib"))
ret.extend(extrajars)
return normclasspath(":".join(ret))
回答by abdul hameed basha
I faced similar issue like this, In my class path there was two jar contains same class, httpcore-4.3 and apache-httpcomponents-httpcore, I have removed apache-httpcomponents-httpcore from class path solved the issue.
我遇到了类似的问题,在我的类路径中有两个 jar 包含相同的类,httpcore-4.3 和 apache-httpcomponents-httpcore,我已经从类路径中删除了 apache-httpcomponents-httpcore 解决了这个问题。
回答by user3048960
I had the below jar files in the path inside the plugin folder:
./var/lib/jenkins/plugins/build-pipeline-plugin/WEB-INF/lib/httpcore-4.2.1.jar
./var/lib/jenkins/plugins/git-client/WEB-INF/lib/httpcore-4.3.2.jar
./var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/httpcore-4.2.4.jar
我在插件文件夹内的路径中有以下 jar 文件:./ var/lib/ jenkins/ plugins/ build- pipeline-plugin/ WEB- INF/
lib/
httpcore- 4.2.1.jar ./var/lib/jenkins /plugins/git-client/WEB-INF/lib/httpcore-4.3.2.jar
./var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/httpcore-4.2.4.jar
After, I removed the below file, it worked for me
/var/lib/jenkins/plugins/build-pipeline-plugin/WEB-INF/lib/httpcore-4.2.1.jar
之后,我删除了以下文件,它对我
有用 /var/lib/jenkins/plugins/build-pipeline-plugin/WEB-INF/lib/httpcore-4.2.1.jar