Apache camel apache camel java中的NoSuchMethodError
我运行了以下代码:Apache camel apache camel java中的NoSuchMethodError,apache-camel,activemq,Apache Camel,Activemq,我运行了以下代码: package com.dinesh.example4; import javax.jms.ConnectionFactory; //import org.apache.camel.support.HeaderFilterStrategyComponent; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.camel.CamelContext; import org.apache
package com.dinesh.example4;
import javax.jms.ConnectionFactory;
//import org.apache.camel.support.HeaderFilterStrategyComponent;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.Component;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
//import org.apache.camel.impl.*;
public class FileToActiveMQ {
public static void main(String[] args) throws Exception {
CamelContext context = new DefaultCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
context.addComponent("jms",JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:input_box?noop=true")
.to("activemq:queue:my_queue");
}
});
while(true)
context.start();
}
}
用于将数据从输入框文件夹转换为activemq
我得到以下错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.camel.impl.HeaderFilterStrategyComponent.<init>(Ljava/lang/Class;)V
at org.apache.camel.component.jms.JmsComponent.<init>(JmsComponent.java:71)
at org.apache.camel.component.jms.JmsComponent.<init>(JmsComponent.java:87)
at org.apache.camel.component.jms.JmsComponent.jmsComponent(JmsComponent.java:102)
at org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge(JmsComponent.java:127)
at com.dinesh.example4.FileToActiveMQ.main(FileToActiveMQ.java:18)
线程“main”java.lang.NoSuchMethodError中出现异常:org.apache.camel.impl.HeaderFilterStrategyComponent.(Ljava/lang/Class;)V
位于org.apache.camel.component.jms.JmsComponent(JmsComponent.java:71)
位于org.apache.camel.component.jms.JmsComponent(JmsComponent.java:87)
位于org.apache.camel.component.jms.JmsComponent.JmsComponent(JmsComponent.java:102)
位于org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge(JmsComponent.java:127)
在com.dinesh.example4.FileToActiveMQ.main上(FileToActiveMQ.java:18)
此处为上述代码的第18行:
addRoutes(新RouteBuilder(){
Pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dinesh</groupId>
<artifactId>camel-application1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.camel/camel-core -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.14.4</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.24.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-activemq</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
</project>
4.0.0
com.dinesh
camel-application1
0.0.1-快照
org.apache.camel
驼芯
2.14.4
org.apache.camel
骆驼jms
2.24.0
org.apache.camel
camel-activemq
3.0.0
请帮助。根据您的POM,您可以混合3种不同的Camel版本:2.14.4、2.24.0和3.0.0 所有Camel组件都必须使用相同的版本,正如@claus ibsen已经评论的那样 例如,像下面的示例那样执行(使用框架版本的属性,并在其所有依赖项中使用它) 但是,正如Sneharghya已经回答的那样,Camel 2.x没有
Camel-activemq
,而是可以使用activemq的依赖项activemq-Camel
因此POM应该是这样的,但我认为驼色版本可能会有所不同
<properties>
<amq.version>5.15.4</amq.version>
<camel.version>2.19.5</camel.version>
</properties>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>${amq.version}</version>
</dependency>
.camel activemq
不适用于早于3.0的版本。
如果要继续使用camel 2.24.3,请从pom文件中删除camel-activemq
依赖项并添加
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.15.13</version>
</dependency>
org.apache.activemq
activemq骆驼
5.15.13
1.更新类
有两个问题
- 您正在用一个名称
jms
注册组件,并将消息发送到不同的组件activemq
。它们应该是相同的
- 您正在执行while循环,而while循环多次启动上下文
2.替换pom中的依赖项如下:
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.15.7</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.15.7</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.15.7</version>
</dependency>
</dependencies>
org.apache.camel
驼芯
2.25.1
org.apache.camel
骆驼jms
2.25.1
org.apache.activemq
activemq客户端
5.15.7
org.apache.activemq
activemq骆驼
5.15.7
org.apache.activemq
activemq池
5.15.7
听起来您的类路径上有混合版本的Camel jar。请确保只使用相同的版本。org.apache.Camel core 2.14.4 org.apache.Camel jms 2.24.0 org.apache.Camel activemq 3.0.0如何获得相同的版本?请告诉bec,我是apache Camel框架的新手。谢谢提前。我更新了我的答案。它实际上不是一个驼峰,而是一个Maven问题。在更新之后,会出现另一个错误,但是对于上面的pom.xml,activemq版本与其他2个依赖项不同。因此我相应地更新了。现在出现了以下错误:线程“main”中出现异常java.lang.NoSuchMethodError:org.apache.activemq.camel.component.ActiveMQComponent.getMessageCreatedStrategy()Lorg/apache/camel/component/jms/MessageCreatedStrategy;位于context.start()处;在上面的代码中。很抱歉,我没有注意到新的camel-activemq
组件。我修复了我的答案,但是NoSuchMethodError
仍然是一个混合版本的问题在如上更新后,现在出现了以下错误。线程“main”中出现异常java.lang.NoSuchMethodError:org.apache.activemq.camel.component.ActiveMQComponent.getMessageCreatedStrategy()Lorg/apache/camel/component/jms/MessageCreatedStrategy;,位于context.start()处。实际上,我使用的是activemq版本5.15.4,为此,请告诉我camel core的版本。在maven pom.xml中。使用activemq camel版本5.15.4。camel 2.24.3就可以了!不,它不工作,再次出现异常。对于我来说。activemq:5.8.0,camel core-2.12.1没有错误(在运行时也有错误)。但是我的Activemq版本是5.15.4,因此无法输出。因此,请告诉我Activemq 5.15.4的确切版本是什么?在maven pom中。尝试使用camel 2.19.5Hi,我只想使用Activemq。请告诉这些示例的代码。bec'我从internet下载了Activemq并运行了它。现在我尝试了它。没有运行时错误/例外ns.但是输出不来。我在我的项目资源管理器中有input_box文件夹,我正在创建一个文本文件,我必须转到activemq服务器(文件未填充。文件消耗消息不断出现,我认为activemq有问题。不确定。让我们来看看。
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>2.25.1</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.15.7</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.15.7</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
<version>5.15.7</version>
</dependency>
</dependencies>