java.lang.NoSuchMethodError 当 运行 Logstash 插件时
java.lang.NoSuchMethodError when running Logstash plugin
我有一个 java 程序可以将数据转换成 JSON 格式。
我能够成功地将程序构建到 jar 文件中,并在独立程序中成功使用 jar 的功能。
我为调用此 jar 的 Logstash 创建了一个 jruby 插件。
当 运行 Logstash:
gem build logstash-filter-example.gemspec &&
../../logstash-5.6.7.freshinstall/bin/logstash-plugin install logstash-filter-example-0.1.1.gem &&
../../logstash-5.6.7.freshinstall/bin/logstash -e 'input { stdin{} } filter { example {} } output {stdout { codec => rubydebug }}'
我收到以下错误:
/dataservice/DataServiceClient.java:156:in `parseQueryRowEntry': java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.node.JsonNodeFactory.numberNode(Ljava/math/BigDecimal;)Lcom/fasterxml/jackson/databind/node/NumericNode;
from com/mike/dataservice/DataServiceClient.java:93:in `toJsonObject'
from com/mike/dataservice/DataServiceClient.java:66:in `getData'
from java/lang/reflect/Method.java:498:in `invoke'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/vendor/local_gems/ecdbfdf7/logstash-filter-example-0.1.1/lib/logstash/filters/example.rb:49:in `filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:145:in `do_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:164:in `multi_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:164:in `multi_filter'
from org/jruby/RubyArray.java:1613:in `each'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:161:in `multi_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:161:in `multi_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filter_delegator.rb:46:in `multi_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filter_delegator.rb:46:in `multi_filter'
from (eval):42:in `filter_func'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/pipeline.rb:398:in `filter_batch'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/pipeline.rb:398:in `filter_batch'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/pipeline.rb:379:in `worker_loop'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/pipeline.rb:342:in `start_workers'
from java/lang/Thread.java:748:in `run'
由于某种原因,无法识别 numberNode() 方法。
但是,当 运行 我的 jar 带有独立的 jruby 程序时,我没有问题,即使使用 Logstash 的本地安装的 jruby 实例也是如此。此外,该程序成功地使用了我的 jar 文件中的一些方法...... numberNode(Ljava/math/BigDecimal;) 是唯一无法识别的方法。为什么 Logstash 看不到这个?
很可能 Logstash 将 JsonNodeFactory
添加到 classpath,这与您的应用程序期望的版本不兼容。该方法围绕 jackson-databind-2.10.
重构
您可以通过检查从何处加载 class 来验证它。例如。
System.out.println(JsonNodeFactory.class.getProtectionDomain().getCodeSource().getLocation());
我有一个 java 程序可以将数据转换成 JSON 格式。 我能够成功地将程序构建到 jar 文件中,并在独立程序中成功使用 jar 的功能。
我为调用此 jar 的 Logstash 创建了一个 jruby 插件。 当 运行 Logstash:
gem build logstash-filter-example.gemspec &&
../../logstash-5.6.7.freshinstall/bin/logstash-plugin install logstash-filter-example-0.1.1.gem &&
../../logstash-5.6.7.freshinstall/bin/logstash -e 'input { stdin{} } filter { example {} } output {stdout { codec => rubydebug }}'
我收到以下错误:
/dataservice/DataServiceClient.java:156:in `parseQueryRowEntry': java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.node.JsonNodeFactory.numberNode(Ljava/math/BigDecimal;)Lcom/fasterxml/jackson/databind/node/NumericNode;
from com/mike/dataservice/DataServiceClient.java:93:in `toJsonObject'
from com/mike/dataservice/DataServiceClient.java:66:in `getData'
from java/lang/reflect/Method.java:498:in `invoke'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/vendor/local_gems/ecdbfdf7/logstash-filter-example-0.1.1/lib/logstash/filters/example.rb:49:in `filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:145:in `do_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:164:in `multi_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:164:in `multi_filter'
from org/jruby/RubyArray.java:1613:in `each'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:161:in `multi_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filters/base.rb:161:in `multi_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filter_delegator.rb:46:in `multi_filter'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/filter_delegator.rb:46:in `multi_filter'
from (eval):42:in `filter_func'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/pipeline.rb:398:in `filter_batch'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/pipeline.rb:398:in `filter_batch'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/pipeline.rb:379:in `worker_loop'
from /Users/michael.dobrin/compilationsFromSource/logstash-5.6.7/logstash-5.6.7.freshinstall/logstash-core/lib/logstash/pipeline.rb:342:in `start_workers'
from java/lang/Thread.java:748:in `run'
由于某种原因,无法识别 numberNode() 方法。 但是,当 运行 我的 jar 带有独立的 jruby 程序时,我没有问题,即使使用 Logstash 的本地安装的 jruby 实例也是如此。此外,该程序成功地使用了我的 jar 文件中的一些方法...... numberNode(Ljava/math/BigDecimal;) 是唯一无法识别的方法。为什么 Logstash 看不到这个?
很可能 Logstash 将 JsonNodeFactory
添加到 classpath,这与您的应用程序期望的版本不兼容。该方法围绕 jackson-databind-2.10.
您可以通过检查从何处加载 class 来验证它。例如。
System.out.println(JsonNodeFactory.class.getProtectionDomain().getCodeSource().getLocation());