如何解决此错误?

时间:2014-01-06 08:41:15

标签: java jboss6.x

我已经在jboss中成功配置了Jms队列。配置完后我已经得到了jboss这样的控制台消息

[org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS [6.0.0.Final "Neo"] Started in 1m:2s:271ms
[org.hornetq.ra.inflow.HornetQActivation] Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@e2b54 destination=queue/MyQueue destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)
INFO  [org.hornetq.ra.inflow.HornetQActivation] Reconnected with HornetQ

之后我运行了示例客户端程序,使用下面的代码

将消息发送到该队列
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.NamingException;
import com.theopentutorials.mdb.to.Employee;
import com.theopentutorials.utility.ClientUtility;

    public class QueueSenderDemo{
        private static final String QUEUE_LOOKUP = "queue/MyQueue";
        private static final String CONNECTION_FACTORY = "ConnectionFactory";

        public static void main(String[] args) {
            sendMessageToQueue();
            sendObjectMessageToQueue();
        }

        public static void sendMessageToQueue() {
            try {
                Context context = ClientUtility.getInitialContextForClient();
                QueueConnectionFactory factory = (QueueConnectionFactory) context
                        .lookup(CONNECTION_FACTORY);
                QueueConnection connection = factory.createQueueConnection();
                QueueSession session = connection.createQueueSession(false,
                        QueueSession.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue) context.lookup(QUEUE_LOOKUP);

                QueueSender sender = session.createSender(queue);
                TextMessage message = session.createTextMessage();
                message.setText("Welcome to EJB3");
                sender.send(message);
                session.close();
            } catch (NamingException e) {
                e.printStackTrace();
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }

        public static void sendObjectMessageToQueue() {
            try {
                Context context = ClientUtility.getInitialContextForClient();
                QueueConnectionFactory factory = (QueueConnectionFactory) context
                        .lookup(CONNECTION_FACTORY);
                QueueConnection connection = factory.createQueueConnection();
                QueueSession session = connection.createQueueSession(false,
                        QueueSession.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue) context.lookup(QUEUE_LOOKUP);

                QueueSender sender = session.createSender(queue);
                ObjectMessage message = session.createObjectMessage();
                Employee emp = new Employee();
                emp.setDesignation("Developer");
                emp.setSalary(25000);
                emp.setName("ABC");
                emp.setId(1);
                message.setObject(emp);
                sender.send(message);
                session.close();
            } catch (Exception e) {
                e.printStackTrace();
            } /*catch (JMSException e) {
                e.printStackTrace();
            }*/
        }
    }

最后我收到以下错误消息

javax.naming.NamingException: Could not dereference object [Root exception is java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization]
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1135)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:690)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.theopentutorials.client.QueueSenderDemo.sendMessageToQueue(QueueSenderDemo.java:33)
    at com.theopentutorials.client.QueueSenderDemo.main(QueueSenderDemo.java:25)
Caused by: java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization
    at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:713)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    at java.io.Objpackage com.theopentutorials.client;ectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at org.hornetq.jms.referenceable.SerializableObjectRefAddr.deserialize(SerializableObjectRefAddr.java:79)
    at org.hornetq.jms.referenceable.ConnectionFactoryObjectFactory.getObjectInstance(ConnectionFactoryObjectFactory.java:43)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
    at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1110)
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1127)
    ... 5 more
Caused by: java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization
    at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:587)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1582)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
    ... 16 more
javax.naming.NamingException: Could not dereference object [Root exception is java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization]
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1135)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:690)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
    at javax.naming.InitialContext.lookup(InitialContext.java:392)
    at com.theopentutorials.client.QueueSenderDemo.sendObjectMessageToQueue(QueueSenderDemo.java:55)
    at com.theopentutorials.client.QueueSenderDemo.main(QueueSenderDemo.java:26)
Caused by: java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization
    at java.io.ObjectStreamClass.checkDeserialize(ObjectStreamClass.java:713)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
    at org.hornetq.jms.referenceable.SerializableObjectRefAddr.deserialize(SerializableObjectRefAddr.java:79)
    at org.hornetq.jms.referenceable.ConnectionFactoryObjectFactory.getObjectInstance(ConnectionFactoryObjectFactory.java:43)
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304)
    at org.jnp.interfaces.NamingContext.getObjectInstance(NamingContext.java:1110)
    at org.jnp.interfaces.NamingContext.getObjectInstanceWrapFailure(NamingContext.java:1127)
    ... 5 more
Caused by: java.io.InvalidClassException: org.hornetq.core.client.impl.ClientSessionFactoryImpl; class invalid for deserialization
    at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:587)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1582)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1495)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1731)
    ... 16 more

我在类路径中包含了以下jar文件 的 jbossall-client.jar中,将hornetq-bootsrap.jar,hotnetq-jms.jar,将hornetq-logging.jar,netty.jar,将hornetq-共client.jar中,将hornetq-的JBoss-AS-integration.jar时,JBoss -as-将hornetq-int.jar,将hornetq-core.jar添加

请帮帮我。过去两天我试过这个。

1 个答案:

答案 0 :(得分:0)

最后我已经解决了这个错误。我使用了jboss 6.x。它在 jboss / common / lib 文件夹中有自己的hornetq配置和相应的jar文件。我已经包含了不同的jar文件在classpath中。 所以要么使用任何一个jar文件。它应该解决上面的错误。