ActiveMQConnectionFactory : Unsupported major.minor version 51.0解决方案

本文介绍了解决ActiveMQ集成过程中因JDK版本不兼容导致的问题。通过更换与当前JDK版本相匹配的ActiveMQ版本,成功解决了运行时报错的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先说明一下

公司产品是一个比较老的东西,基于jdk1.6版本.


现需要将activeMQ集成到产品中,使用的jar包是:activemq-all-5.11.1.jar

 集成后运行始终报错:ActiveMQConnectionFactory : Unsupported major.minor version 51.0


通过查询这是由于编译使用的jdk版本不兼容导致的错误.初步是使用高版本jdk编译的class文件放在低版本jdk环境中运行就会出现这样的错误.


查看activemq-all-5.11.1.jar的MANIFEST.MF文件:

Manifest-Version: 1.0
Implementation-Vendor: The Apache Software Foundation
Implementation-Title: ActiveMQ :: All JAR bundle
Implementation-Version: 5.11.1
Implementation-Vendor-Id: org.apache.activemq
Built-By: art
Build-Jdk: 1.7.0_60
Specification-Vendor: The Apache Software Foundation
Specification-Title: ActiveMQ :: All JAR bundle
Created-By: Apache Maven 3.2.1
Specification-Version: 5.11.1
Archiver-Version: Plexus Archiver


Build-Jdk: 1.7.0_60  表示是使用jdk1.7编译的


所以我又下载了一个activemq-all-5.9.0.jar  :  Build-Jdk: 1.6.0_51

替换之前的jar包,运行不再报错


详细说一下一下代码:package com.mcloud.market.mq; import com.mcloud.common.constant.Constants; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.command.ActiveMQQueue; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jms.config.JmsListenerContainerFactory; import org.springframework.jms.config.SimpleJmsListenerContainerFactory; import org.springframework.jms.core.JmsMessagingTemplate; import javax.jms.ConnectionFactory; import javax.jms.Queue; @Configuration public class ActiveMQConfig { @Value("${spring.activemq.broker-url}") private String brokerUrl; @Value("${spring.activemq.user}") private String username; @Value("${spring.activemq.password}") private String password; @Bean public Queue queue() { return new ActiveMQQueue(Constants.PREFIX + ".amount"); } @Bean(name = "messageQueue") public Queue amountQueue() { return new ActiveMQQueue(Constants.PREFIX + ".message"); } // 在Queue模式中,对消息的监听需要对containerFactory进行配置 @Bean("queueListener") public JmsListenerContainerFactory<?> queueJmsListenerContainerFactory(ConnectionFactory connectionFactory) { SimpleJmsListenerContainerFactory factory = new SimpleJmsListenerContainerFactory(); factory.setConnectionFactory(connectionFactory); factory.setPubSubDomain(false); return factory; } @Bean public ConnectionFactory connectionFactory() { return new ActiveMQConnectionFactory(username, password, brokerUrl); } @Bean public JmsMessagingTemplate jmsMessageTemplate() { return new JmsMessagingTemplate(connectionFactory()); } }
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值