【问题标题】:How to resolve this Error?如何解决此错误?
【发布时间】:2014-01-06 08:41:15
【问题描述】:

我已经在 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-common-client.jar,hornetq-jboss-as-integration.jar,jboss -as-hornetq-int.jar,hornetq-core.jar

请帮帮我。我已经尝试了这两天。

【问题讨论】:

  • No.not like that.tried sample jms application using jboss

标签: java jboss6.x


【解决方案1】:

我终于解决了这个错误。我使用了 jboss 6.x。所以它在 jboss/common/lib 文件夹中有自己的 hornetq 配置和相应的 jar 文件。我包含了不同的 jar 文件在类路径中。 所以要么使用任何一个jar文件。它应该可以解决上述错误。

【讨论】:

    猜你喜欢
    • 2017-12-12
    • 2012-02-14
    • 2015-04-12
    • 2016-06-21
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多