ActiveMQ的NoSuchMethodError [英] NoSuchMethodError with ActiveMQ

查看:112
本文介绍了ActiveMQ的NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.lang.NoSuchMethodError: org.apache.activemq.thread.TaskRunnerFactory.setThreadClassLoader(Ljava/lang/ClassLoader;)V
    at org.apache.activemq.broker.BrokerService.getTaskRunnerFactory(BrokerService.java:1265)
    at org.apache.activemq.broker.BrokerService.createRegionBroker(BrokerService.java:2346)
    at org.apache.activemq.broker.BrokerService.createBroker(BrokerService.java:2305)
    at org.apache.activemq.broker.BrokerService.getBroker(BrokerService.java:1017)
    at org.apache.activemq.broker.BrokerService.getAdminConnectionContext(BrokerService.java:2576)
    at org.apache.activemq.broker.BrokerService.startVirtualConsumerDestinations(BrokerService.java:2717)
    at org.apache.activemq.broker.BrokerService.startDestinations(BrokerService.java:2567)
    at org.apache.activemq.broker.BrokerService.doStartBroker(BrokerService.java:726)
    at org.apache.activemq.broker.BrokerService.startBroker(BrokerService.java:720)
    at org.apache.activemq.broker.BrokerService.start(BrokerService.java:623)
    at com.bp.pnc.publisher.app.PncPublisherApplication.main(PncPublisherApplication.java:77)

我使用的代码是

BrokerService broker = new BrokerService();
TransportConnector connector = new TransportConnector();
connector.setUri(new URI("tcp://localhost:61616"));
broker.addConnector(connector);
broker.start();

问题发生在broker.start()方法。我正在使用activemq 5.14.0。我正在使用Java 7.
我查看了文档以及发生这种情况的确切行。

The problem occurs at broker.start() method. I am using activemq 5.14.0. I am using Java 7. I looked at the documentation and exact line where this is happening.

this.taskRunnerFactory.setThreadClassLoader(this.getClass()。getClassLoader());

推荐答案

出现此错误的原因不同:

There are different reasons why this error can occur:


  • 运行应用程序使用较旧的activemq.jar而不是用于编译源代码的那个

  • 您的应用程序在其类路径中有更多的jar,其中一个包含activemq的类(因为它使用了类本身)。如果在activemq.jar之前加载该jar(即它出现在acitvemq.jar的前面),则使用旧版本。

如果是后者,您可以将以下代码放入您的类中(在您在问题中显示的代码之前),以查看该类的加载位置:

If the latter, you can put the following code into your class (before the code you shown in your question) to see where the class is loaded from:

Class clazz = TaskRunnerFactory.class;
String name = clazz.getName().replace('.', '/') + ".class";
String loc = clazz.getClassLoader().getResource(name).toString();
System.out.println(loc);

这篇关于ActiveMQ的NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆