Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何处理运行时错误:java.lang.NoSuchMethodError_Java_Maven_Gradle_Dependencies - Fatal编程技术网

如何处理运行时错误:java.lang.NoSuchMethodError

如何处理运行时错误:java.lang.NoSuchMethodError,java,maven,gradle,dependencies,Java,Maven,Gradle,Dependencies,我有一个依赖性很强的应用程序。一个依赖项是ActiveMQ Artemis。在Maven模块的pom.xml中,我将版本从2.4.0更新为2.10.0 <dependency> <groupId>org.apache.activemq</groupId> <artifactId>artemis-server</artifactId> <version>2.10.0</version> </

我有一个依赖性很强的应用程序。一个依赖项是ActiveMQ Artemis。在Maven模块的pom.xml中,我将版本从2.4.0更新为2.10.0

<dependency>
   <groupId>org.apache.activemq</groupId>
   <artifactId>artemis-server</artifactId>
   <version>2.10.0</version>
</dependency>
<dependency>
   <groupId>org.apache.activemq</groupId>
   <artifactId>artemis-commons</artifactId>
   <version>2.10.0</version>
</dependency>
<dependency>
   <groupId>org.apache.activemq</groupId>
   <artifactId>artemis-jms-client-all</artifactId>
   <version>2.10.0</version>
</dependency>
代理客户端通过来自Camel的sjms组件连接:

org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory cf = new ActiveMQJMSConnectionFactory(url);
SjmsComponent component = new SjmsComponent();
component.setConnectionFactory(cf);
context.addComponent("sjms", component);
我在另一个使用Gradle 5.6.2构建/编译的应用程序中使用了这个Maven模块。此应用程序还包含Apache Camel 2.24.2和Apache ActiveMQ 5.5.10的库

应用程序正常编译,但在运行时我得到一个“NoSuchMethodError”:

从日志记录中:

2019-09-21 03:03:00.883 WARN 4984 --- [ XNIO-2 task-14] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.activemq.artemis.utils.ClassloadingUtil.loadProperty(Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
java.lang.NullPointerException
   at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.finalize(ActiveMQConnectionFactory.java:961)
   at java.lang.System$2.invokeFinalize(System.java:1270)
   at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:102)
   at java.lang.ref.Finalizer.access$100(Finalizer.java:34)
   at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:217)
基于这篇文章,我运行了“gradlew dependencies”

因此,Artemis代理实际上在2.4.0版本下运行,而客户端在2.10.0版本下运行(使它们不兼容)

一该条规定:

“最后,我们需要决定两个版本中的哪一个真正需要满足这两个依赖项。通常,这是较新的版本,因为大多数框架在某一点上是向后兼容的。但是,它可能是另一种方式,或者我们甚至可能根本无法解决冲突。”

要强制在2.10.0上同时运行,我在build.gradle文件中显式声明:

configurations.all {
  resolutionStrategy {  
    force 'org.apache.activemq:artemis-core-client:2.10.0', 'org.apache.activemq:artemis-broker:2.10.0','org.apache.activemq:artemis-commons:2.10.0','org.apache.activemq:artemis-selector:2.10.0','org.apache.activemq:artemis-journal:2.10.0'
  }
}

compile group: 'org.apache.activemq', name: 'artemis-core-client', version: '2.10.0'
compile group: 'org.apache.activemq', name: 'artemis-commons', version: '2.10.0'
compile group: 'org.apache.activemq', name: 'artemis-server', version: '2.10.0'
compile group: 'org.apache.activemq', name: 'artemis-selector', version: '2.10.0'
compile group: 'org.apache.activemq', name: 'artemis-journal', version: '2.10.0'
在此“gradlew依赖项”之后:

问题

代理库和客户端库都在同一版本上,应用程序似乎工作正常。但这让我感到不安:

  • 在自动解决依赖关系的情况下,如何在应用程序的发行说明中写入库已更新,而实际上使用的是两年前的版本?作为一名开发人员,我如何知道事实并非如此
  • 如何读取gradlew依赖项输出?迫使使用旧版本“2.4.0”的根本原因是什么
  • 强制使用新版本真的是一个很好的解决方案吗?或者在覆盖自动依赖解决时是否存在预期问题
  • 只有通过
    force
    、配置级别
    force
    或替换规则,才能降级Gradle 6.0之前的版本。您的构建中有一些东西使用这些技术之一来强制降低版本
  • 要调查特定库的版本,请使用
    dependencyInsight
    任务获取有关为什么选择模块的特定版本的更详细报告。 类似于
    /gradlew dependencyInsight--configuration--dependency artemis server
    ,其中
    可以是
    compileClasspath
    runtimeClasspath
    或更特定于项目的内容
  • 一旦您弄清楚为什么
    2.10.0
    被降级为
    2.4.0
    ,您就可以使用与
    force
    不同的解决方案来获得所需的版本
  • 只有通过
    force
    、配置级别
    force
    或替换规则,才能降级Gradle 6.0之前的版本。您的构建中有一些东西使用这些技术之一来强制降低版本
  • 要调查特定库的版本,请使用
    dependencyInsight
    任务获取有关为什么选择模块的特定版本的更详细报告。 类似于
    /gradlew dependencyInsight--configuration--dependency artemis server
    ,其中
    可以是
    compileClasspath
    runtimeClasspath
    或更特定于项目的内容
  • 一旦您弄清楚为什么
    2.10.0
    被降级为
    2.4.0
    ,您就可以使用与
    force
    不同的解决方案来获得所需的版本

  • 值得注意的是,更新版本的ActiveMQ Artemis客户端不一定与旧版本的代理不兼容。假设它们通过网络连接,则它们应该兼容。然而,在我看来,实际上有一个较新的客户机和一个较旧的代理运行在同一个JVM中,没有任何类型的类加载器隔离,正如您所看到的,这通常不会很好地工作。我不能真正解决Gradle问题,因为我对它不太熟悉,但无论如何,你的问题中有太多不同的问题。你应该把你的问题集中到一个问题上,这样正确的答案很容易识别。如果你有多个不同的问题,那么你应该实际创建多个问题,而不是将它们捆绑在一篇文章中。对于第2点,你可以使用
    gradle-q dependencyInsight--dependency artemis server--configuration compile
    。对于第2点,gradle通常解析为更高版本(2.10)万一发生冲突。在这里,使用2.4应该有一个明显的原因(但您应该共享整个build.gradle文件)。gradle语句似乎很有用,但这只提供了maven模块(其中包含其他依赖项)使用不是根本原因。值得注意的是,ActiveMQ Artemis客户端的较新版本不一定与旧版本的代理不兼容。假设它们通过网络连接,则它们应该兼容。然而,在我看来,实际上有一个较新的客户机和一个较旧的代理运行在同一个JVM中,没有任何类型的类加载器隔离,正如您所看到的,这通常不会很好地工作。我不能真正解决Gradle问题,因为我对它不太熟悉,但无论如何,你的问题中有太多不同的问题。你应该把你的问题集中到一个问题上,这样正确的答案很容易识别。如果你有多个不同的问题,那么你应该实际创建多个问题,而不是将它们捆绑在一篇文章中。对于第2点,你可以使用
    gradle-q dependencyInsight--dependency artemis server--configuration compile
    。对于第2点,gradle通常解析为更高版本(2.10)万一发生冲突。这里使用的是2.4,
    2019-09-21 03:03:00.883 WARN 4984 --- [ XNIO-2 task-14] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by handler execution: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: org.apache.activemq.artemis.utils.ClassloadingUtil.loadProperty(Ljava/lang/ClassLoader;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    java.lang.NullPointerException
       at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.finalize(ActiveMQConnectionFactory.java:961)
       at java.lang.System$2.invokeFinalize(System.java:1270)
       at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:102)
       at java.lang.ref.Finalizer.access$100(Finalizer.java:34)
       at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:217)
    
    |    +--- org.apache.activemq:artemis-server:2.10.0 -> 2.4.0
    |    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.2.Final
    |    |    +--- org.apache.activemq:artemis-commons:2.4.0
    |    |    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.2.Final
    |    |    |    +--- io.netty:netty-buffer:4.1.16.Final -> 4.1.31.Final (*)
    |    |    |    +--- io.netty:netty-transport:4.1.16.Final -> 4.1.31.Final (*)
    |    |    |    +--- io.netty:netty-handler:4.1.16.Final -> 4.1.31.Final (*)
    |    |    |    +--- commons-beanutils:commons-beanutils:1.9.3
    |    |    |    |    +--- commons-logging:commons-logging:1.2
    |    |    |    |    \--- commons-collections:commons-collections:3.2.2
    |    |    |    \--- com.google.guava:guava:19.0 -> 25.1-jre (*)
    |    |    +--- org.apache.activemq:artemis-selector:2.4.0
    |    |    +--- org.apache.activemq:artemis-journal:2.4.0
    |    |    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.2.Final
    |    |    |    +--- org.apache.activemq:artemis-commons:2.4.0 (*)
    |    |    |    \--- org.apache.activemq:artemis-native:2.4.0
    |    |    |         \--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.2.Final
    |    |    +--- org.apache.activemq:artemis-jdbc-store:2.4.0
    |    |    |    +--- org.jboss.logging:jboss-logging:3.3.0.Final -> 3.3.2.Final
    |    |    |    +--- org.apache.activemq:artemis-journal:2.4.0 (*)
    |    |    |    \--- org.apache.activemq:artemis-core-client:2.4.0
    |    |    |         +--- org.jgroups:jgroups:3.6.13.Final -> 3.6.7.Final
    |    |    |         +--- org.apache.activemq:artemis-commons:2.4.0 (*)
    |    |    |         +--- org.apache.johnzon:johnzon-core:0.9.5 -> 1.1.10
    |    |    |         +--- io.netty:netty-transport-native-epoll:4.1.16.Final -> 4.1.31.Final (*)
    |    |    |         +--- io.netty:netty-transport-native-kqueue:4.1.16.Final -> 4.1.31.Final (*)
    |    |    |         \--- io.netty:netty-codec-http:4.1.16.Final -> 4.1.31.Final (*)
    |    |    +--- org.apache.activemq:artemis-core-client:2.4.0 (*)
    |    |    \--- io.netty:netty-all:4.1.16.Final -> 4.1.9.Final
    |    +--- org.apache.activemq:artemis-commons:2.10.0 -> 2.4.0 (*)
    |    +--- org.apache.activemq:artemis-jms-client-all:2.10.0
    
    configurations.all {
      resolutionStrategy {  
        force 'org.apache.activemq:artemis-core-client:2.10.0', 'org.apache.activemq:artemis-broker:2.10.0','org.apache.activemq:artemis-commons:2.10.0','org.apache.activemq:artemis-selector:2.10.0','org.apache.activemq:artemis-journal:2.10.0'
      }
    }
    
    compile group: 'org.apache.activemq', name: 'artemis-core-client', version: '2.10.0'
    compile group: 'org.apache.activemq', name: 'artemis-commons', version: '2.10.0'
    compile group: 'org.apache.activemq', name: 'artemis-server', version: '2.10.0'
    compile group: 'org.apache.activemq', name: 'artemis-selector', version: '2.10.0'
    compile group: 'org.apache.activemq', name: 'artemis-journal', version: '2.10.0'
    
    |    +--- org.apache.activemq:artemis-server:2.10.0
    |    |    +--- org.jboss.logging:jboss-logging:3.4.0.Final -> 3.3.2.Final
    |    |    +--- org.jboss.logmanager:jboss-logmanager:2.1.10.Final
    |    |    |    \--- org.wildfly.common:wildfly-common:1.5.1.Final
    |    |    +--- org.apache.activemq:artemis-commons:2.10.0
    |    |    |    +--- org.jboss.logging:jboss-logging:3.4.0.Final -> 3.3.2.Final
    |    |    |    +--- io.netty:netty-buffer:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |    +--- io.netty:netty-transport:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |    +--- io.netty:netty-handler:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |    \--- commons-beanutils:commons-beanutils:1.9.3
    |    |    |         +--- commons-logging:commons-logging:1.2
    |    |    |         \--- commons-collections:commons-collections:3.2.2
    |    |    +--- org.apache.activemq:artemis-selector:2.10.0
    |    |    |    \--- org.apache.activemq:artemis-commons:2.10.0 (*)
    |    |    +--- org.apache.activemq:artemis-journal:2.10.0
    |    |    |    +--- org.jboss.logging:jboss-logging:3.4.0.Final -> 3.3.2.Final
    |    |    |    +--- org.apache.activemq:artemis-commons:2.10.0 (*)
    |    |    |    +--- org.apache.activemq:activemq-artemis-native:1.0.0
    |    |    |    |    +--- org.jboss.logging:jboss-logging:3.3.1.Final -> 3.3.2.Final
    |    |    |    |    \--- org.jboss.logmanager:jboss-logmanager:2.0.3.Final -> 2.1.10.Final (*)
    |    |    |    +--- io.netty:netty-buffer:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |    \--- io.netty:netty-common:4.1.34.Final -> 4.1.31.Final
    |    |    +--- org.apache.activemq:artemis-jdbc-store:2.10.0
    |    |    |    +--- org.jboss.logging:jboss-logging:3.4.0.Final -> 3.3.2.Final
    |    |    |    +--- org.apache.activemq:artemis-commons:2.10.0 (*)
    |    |    |    +--- org.apache.activemq:artemis-journal:2.10.0 (*)
    |    |    |    \--- org.apache.activemq:artemis-core-client:2.10.0
    |    |    |         +--- org.jgroups:jgroups:3.6.13.Final -> 3.6.7.Final
    |    |    |         +--- org.apache.activemq:artemis-commons:2.10.0 (*)
    |    |    |         +--- org.apache.johnzon:johnzon-core:0.9.5 -> 1.1.10
    |    |    |         +--- io.netty:netty-transport-native-epoll:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |         +--- io.netty:netty-transport-native-kqueue:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |         +--- io.netty:netty-codec-http:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |         +--- io.netty:netty-buffer:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |         +--- io.netty:netty-transport:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |         +--- io.netty:netty-handler:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |         +--- io.netty:netty-codec:4.1.34.Final -> 4.1.31.Final (*)
    |    |    |         \--- io.netty:netty-common:4.1.34.Final -> 4.1.31.Final
    |    |    +--- org.apache.activemq:artemis-core-client:2.10.0 (*)
    |    |    +--- org.apache.activemq:activemq-artemis-native:1.0.0 (*)