Karaf中Camel-ActiveMQ组件初始化报错:JMSContext类未找到
问题详情
环境
- Karaf 4.4.3
- Camel 3.20.5
Blueprint配置的ActiveMQ组件
<bean id="activemq" class="org.apache.camel.component.activemq.ActiveMQComponent"> <property name="brokerURL" value="tcp://localhost:61616" /> <property name="username" value="karaf" /> <property name="password" value="karaf" /> </bean>
启动报错
org.osgi.service.blueprint.container.ComponentDefinitionException: Error when instantiating bean activemq of class org.apache.camel.component.activemq.ActiveMQComponent ... Caused by: java.lang.NoClassDefFoundError: javax/jms/JMSContext ... Caused by: java.lang.ClassNotFoundException: javax.jms.JMSContext not found by org.apache.geronimo.specs.geronimo-jms_1.1_spec [203]
已安装特性
<feature>transaction</feature> <feature>jndi</feature> <feature>pax-jdbc-config</feature> <feature>pax-jdbc-postgresql</feature> <feature>pax-jdbc-pool-dbcp2</feature> <feature>jdbc</feature> <feature>jms</feature> <feature>activemq-client</feature> <feature>pax-jdbc</feature> <feature dependency="true">aries-blueprint</feature> <feature>cxf</feature> <feature>camel-activemq</feature>
已尝试操作
- 初始化
ActiveMQConnectionFactory时触发相同错误 - 执行
bundle:install mvn:javax.jms/javax.jms-api/2.0.1安装JMS API包,问题未解决 - 移除
ActiveMQComponent后,bundle可正常启动 - ActiveMQ Broker与Karaf在同一环境,通过hawtio连接正常
解决方案
报错核心原因是当前环境使用的JMS 1.1规范包(geronimo-jms_1.1_spec)不包含JMS 2.0才引入的JMSContext接口,需替换为JMS 2.0规范包,操作步骤如下:
- 卸载旧的JMS 1.1规范包
在Karaf控制台执行:
bundle:uninstall org.apache.geronimo.specs.geronimo-jms_1.1_spec
- 安装适配OSGi的JMS 2.0规范包
推荐使用Geronimo的JMS 2.0规范包(兼容性更好):
bundle:install mvn:org.apache.geronimo.specs/geronimo-jms_2.0_spec/1.0-alpha-2
若偏好官方JMS API包,确保选择OSGi兼容版本:
bundle:install mvn:javax.jms/javax.jms-api/2.0.1
- 启动新安装的JMS规范包
执行命令启动(替换<bundle-id>为安装包的ID,可通过bundle:list查看):
bundle:start <bundle-id>
- 可选:通过Karaf特性安装JMS 2.0
若Karaf特性仓库包含jms2特性,可直接执行:
feature:install jms2
该命令会自动处理依赖,无需手动卸载/安装单个包。
内容的提问来源于stack exchange,提问作者k4rnaj1k
相关产品推荐
相关产品推荐

