在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();
}
}