0

首先,我是 JSM 的新手。我正在尝试为 JMS ActiveMQ 创建一个连接池使用连接工厂 ActiveMQConnectionFactory 我成功发送/接收消息,但使用 PooledConnectionFactoryBean 它失败并出现此错误:

Exception in thread "Thread-0" java.lang.NoClassDefFoundError: org/springframework/beans/factory/FactoryBean
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    at jmxproducer.JMXProducerTest.run(JMXProducerTest.java:28)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.FactoryBean
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 14 more
Exception in thread "Thread-1" java.lang.NoClassDefFoundError: org/apache/activemq/pool/PooledConnectionFactoryBean
    at jmxproducer.JMXProducerTest.run(JMXProducerTest.java:28)
    at java.lang.Thread.run(Thread.java:722)
Exception in thread "Thread-2" java.lang.NoClassDefFoundError: org/apache/activemq/pool/PooledConnectionFactoryBean
    at jmxproducer.JMXProducerTest.run(JMXProducerTest.java:28)
    at java.lang.Thread.run(Thread.java:722)
Exception in thread "Thread-3" java.lang.NoClassDefFoundError: org/apache/activemq/pool/PooledConnectionFactoryBean
    at jmxproducer.JMXProducerTest.run(JMXProducerTest.java:28)
    at java

.lang.Thread.run(Thread.java:722)

这是源代码:

package jmxproducer;

import javax.jms.*;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.pool.PooledConnectionFactoryBean;

public class JMXProducerTest implements Runnable {

    private String message;

    public JMXProducerTest(String message) {
        this.message = message;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public void run() {
        try {
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");

            PooledConnectionFactoryBean pool = new PooledConnectionFactoryBean();
            pool.setConnectionFactory(connectionFactory);

            // Create a Connection
            Connection connection = connectionFactory.createConnection();
            connection.start();

            // Create a Session
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create the destination (Topic or Queue)
            Destination destination = session.createQueue("MY.QUEUE");

            // Create a MessageProducer from the Session to the Topic or Queue
            MessageProducer producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            // Create a messages
            TextMessage msg = session.createTextMessage(message);
            producer.send(msg);
            session.close();
            connection.close();
        } catch (JMSException e) {
            e.printStackTrace();
        }
    }
}

我错过了什么?我在类路径中添加了这个 jar:activemq-all-5.8.0.jar

谢谢, kdureidy

4

1 回答 1

0

您是否将 Spring 库添加到您的项目中?

错误

java.lang.ClassNotFoundException: org.springframework.beans.factory.FactoryBean

似乎表明您的项目中缺少 spring-beans-X.jar (其中 X 是您缺少的 Spring 版本)。

于 2013-08-12T01:41:16.703 回答