-1

我是队列的新手。我已经在 J​​BOSS 5.1 EAP 中设置了我的队列,现在在尝试注入队列时得到一个ClassCastException(在 JNDI 的查找中),我在前端使用 flex 并使用 Spring 框架进行 flex。当使用石英作业注入队列时,它运行良好。石英作业是一个单独的项目,与 flex 和 spring 无关。

我阅读了一些可能是罐子问题的地方,我在春天有 JMS 罐子,我尝试移除、更换所有类型的罐子,但没有运气。

        // Step 1. Create an initial context to perform the JNDI lookup.

        InputStream in = this.getClass().getResourceAsStream(
                "/clv2.properties");
        Properties configProp = new Properties();
        configProp.load(in);
        IpAddress = configProp.getProperty("ipaddress");
        port = configProp.getProperty("port");
        inQueueName = configProp.getProperty("inQueueName");
        Properties props = new Properties();
        props.setProperty("java.naming.factory.initial",
                "org.jnp.interfaces.NamingContextFactory");
        props.setProperty("java.naming.factory.url.pkgs",
                "org.jboss.naming");
        // props.setProperty("java.naming.provider.url", host + ":" + port);
        props.setProperty("java.naming.provider.url", "localhost" + ":"
                + 1099);
        // props.setProperty("java.naming.provider.url",
        // "16.181.233.61:1399");
        initialContext = new InitialContext(props);

        // Step 3. Perform a lookup on the Connection Factory
        QueueConnectionFactory cf = (QueueConnectionFactory) initialContext
                .lookup("/ConnectionFactory");
        Queue queue = (Queue) initialContext
                .lookup(/* "/queue/CLVInboundQueue" */inQueueName);
        // Step 4.Create a JMS Connection
        connection = (QueueConnection) cf.createConnection();

        // Step 5. Create a JMS Session
        session = (QueueSession) connection.createSession(false,
                Session.AUTO_ACKNOWLEDGE);

        // Step 6. Create a JMS Message Producer
        // MessageProducer producer = session.createProducer(queue);
        QueueSender queueSender = session.createSender(queue);
        TextMessage textMessage = session.createTextMessage(message);
        textMessage.setLongProperty("Rejected_Message_ID",
                rejected_Message_Id);
        /*
         * BufferedReader reader = new BufferedReader(new
         * InputStreamReader(ClassLoader.class.getResourceAsStream(file)));
         * StringBuilder sb = new StringBuilder(); String line = null;
         * 
         * 
         * while ((line = reader.readLine()) != null) { sb.append(line +
         * "\n"); } String announcementmsg = sb.toString();
         */
        commonlogger.info(textMessage);
        connection.start();
        // producer.send(session.createTextMessage(announcementmsg));
        queueSender.send(textMessage);

这是我注入队列的一段代码。我在“//Step 3. Perform a lookup on the Connection Factory”中得到异常,这是我的堆栈跟踪。

09:22:20,730 ERROR [STDERR] java.lang.ClassCastException: org.jboss.jms.client.JBossConnectionFactory cannot be cast to javax.jms.QueueConnectionFactory
09:22:20,731 ERROR [STDERR]     at com.cat.clv.util.InQueueReinjectMessage.sendMessage(InQueueReinjectMessage.java:63)
09:22:20,731 ERROR [STDERR]     at com.cat.clv.util.RejectedMessageReinject.reProcessedMessage(RejectedMessageReinject.java:65)
09:22:20,731 ERROR [STDERR]     at com.cat.clv.service.ReinjectMessagesServiceImpl.reinjectRejectedMessages(ReinjectMessagesServiceImpl.java:106)
09:22:20,731 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
09:22:20,731 ERROR [STDERR]     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
09:22:20,732 ERROR [STDERR]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
09:22:20,732 ERROR [STDERR]     at java.lang.reflect.Method.invoke(Unknown Source)
09:22:20,732 ERROR [STDERR]     at flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:421)
09:22:20,732 ERROR [STDERR]     at flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:183)
09:22:20,732 ERROR [STDERR]     at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1503)
4

2 回答 2

2

如果您查看JBossConnectionFactory的源代码,您会看到它实现了QueueConnectionFactory

所以这个类转换异常可能是因为:

  1. JBoss 安装错误
  2. 客户端和服务器中不同的 jms.jar

您可以先尝试选项 2 并查看它是否有效,否则您可以检查示例在您的 jboss 安装中是否有效。

于 2012-04-30T17:12:51.693 回答
0

在查找时获取 classCast 异常:classcastexception:weblogic.jms.client.JMSconnectionFactory 无法转换为 javax.jms.QueueConnectionFactory

初始上下文 = 新初始上下文(道具);

    // Step 3. Perform a lookup on the Connection Factory
    QueueConnectionFactory cf = (QueueConnectionFactory) initialContext
            .lookup("/ConnectionFactory");
    Queue queue = (Queue) initialContext
            .lookup(/* "/queue/CLVInboundQueue" */inQueueName);
    // Step 4.Create a JMS Connection
    connection = (QueueConnection) cf.createConnection();

    // Step 5. Create a JMS Session
    session = (QueueSession) connection.createSession(false,
            Session.AUTO_ACKNOWLEDGE);

    // Step 6. Create a JMS Message Producer
    // MessageProducer producer = session.createProducer(queue);
    QueueSender queueSender = session.createSender(queue);
    TextMessage textMessage = session.createTextMessage(message);
    textMessage.setLongProperty("Rejected_Message_ID",
            rejected_Message_Id);
    /*
     * BufferedReader reader = new BufferedReader(new
     * InputStreamReader(ClassLoader.class.getResourceAsStream(file)));
     * StringBuilder sb = new StringBuilder(); String line = null;
     * 
     * 
     * while ((line = reader.readLine()) != null) { sb.append(line +
     * "\n"); } String announcementmsg = sb.toString();
     */
    commonlogger.info(textMessage);
    connection.start();
    // producer.send(session.createTextMessage(announcementmsg));
    queueSender.send(textMessage);
于 2017-06-08T10:07:49.510 回答