The project was not built since its build path is incomplete. Cannot find the class file for org.spr

在eclipse中使用maven搭建activemq时出现的错误

1.Description Resource Path Location Type

The project was not built since its build path is incomplete. Cannot find the class file for org.springframework.beans.factory.BeanNameAware. Fix the build path then try building this project jmstest Unknown Java Problem

2.Description Resource Path Location Type

The type org.springframework.beans.factory.BeanNameAware cannot be resolved. It is indirectly referenced from required .class files AppProducer.java /jmstest/src/main/java/com/imooc/jms/queue line 1 Java Problem

原因是引入的activemq jar包版本不对 造成冲突

错误配置:

<dependencies>

  <dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-all</artifactId>
    <version>5.9.0</version>
    </dependency>

  </dependencies>

将版本改了后就对了:

<dependencies>
  <dependency>
    <groupId>org.apache.activemq</groupId>
    <artifactId>activemq-all</artifactId>
    <version>5.15.4</version>
    </dependency>
  </dependencies>

但是此时需要抛异常:

package com.imooc.jms.queue;


import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;


import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * 
 * @author 35-pxiaodong
 *
 */
public class AppProducer {

private static final String URL="tcp://192.168.66.77:61616";
private static final String QUEUENAME="jmstest";
private static Logger log=LoggerFactory.getLogger(AppProducer.class);

public static void main(String[] args) throws JMSException {
//创建ConnectionFactory
ConnectionFactory connectionFactory=new ActiveMQConnectionFactory();
//创建connection
Connection connection=connectionFactory.createConnection();
//启动连接
connection.start();
//创建会话
Session session=connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
//创建一个目标
Destination destination=session.createQueue(QUEUENAME);
//创建一个生产者
MessageProducer messageProducer=session.createProducer(destination);
for (int i=0;i<100;i++){
//创建消息
TextMessage textMessage=session.createTextMessage("test"+i);
//发布消息
messageProducer.send(textMessage);
log.info("发送消息"+textMessage.getText());
}
//关闭连接
connection.close();
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值