简体   繁体   中英

java.lang.NoSuchMethodError when running Logstash plugin

I have a java program which converts data into JSON format. I am able to successfully build the program into a jar file, and successfully use the jar's functionality in a stand-alone program.

I've created a jruby plugin for Logstash which calls this jar. When running 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 }}'

I receive the following error:

/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'

For some reason, the numberNode() method is not recognized. However, I have no problem when running my jar with a standalone jruby program, even when using Logstash's locally installed instance of jruby. Furthermore, the program successfully uses some methods from my jar file... numberNode(Ljava/math/BigDecimal;) is the only method not recognized. Why can't Logstash see this?

Most likely Logstash adds JsonNodeFactory to classpath which is incompatible with the version that your application expects. The method was refactored around jackson-databind-2.10 .

You can verify it by checking where the class is being loaded from. Eg System.out.println(JsonNodeFactory.class.getProtectionDomain().getCodeSource().getLocation());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM