gpt4 book ai didi

java - Spring Integration 入站 JMS 与 JBoss createConnection() : IllegalArgumentException: ClassCastException

转载 作者:太空宇宙 更新时间:2023-11-04 13:27:21 24 4
gpt4 key购买 nike

我正在尝试进行一个简单的 Spring Integration 测试,以从 JBoss EAP 上的 HornetQ 托管的 JMS 队列中检索消息(在 Windows 7 Pro 上运行的版本 6.4.0.GA),该测试以独立模式运行 (standalone.bat -cstandalone-full.xml)。

使用简单的 Java JMS 程序时,JMS 测试运行良好;现在,我尝试添加 Spring Integration 并收到以下错误:

18:29:03,197 ERROR [org.springframework.jms.listener.DefaultMessageListenerContainer]
(org.springframework.jms.listener.DefaultMessageListenerContainer#0-1)
Could not refresh JMS Connection for destination 'anotherQueue' -
retrying in 5000 ms. Cause: AOP configuration seems to be invalid:
tried calling method [public abstract javax.jms.Connection javax.jms.ConnectionFactory.createConnection()
throws javax.jms.JMSException] on target [HornetQQueue[anotherQueue]];
nested exception is java.lang.IllegalArgumentException: java.lang.ClassCastException@511504f4

Spring 配置文件是:

applicationContext-ordering-inbound-jms-spring-integration.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop=...

<bean id="jndiTemplateBilling" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jboss.as.naming.InitialContextFactory</prop>
<prop key="java.naming.provider.url">remote://localhost:4447</prop>
</props>
</property>
</bean>

<bean id="jndiObjectFactoryBeanBilling" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplateBilling" />

<property name="jndiName" value="java:jboss/exported/jms/queue/anotherQueue" />
<property name="lookupOnStartup" value="false" />
<property name="proxyInterfaces">
<list>
<value>javax.jms.QueueConnectionFactory</value>
<value>javax.jms.TopicConnectionFactory</value>
<value>java.io.Externalizable</value>
</list>
</property>
</bean>

<bean id="jndiDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplateBilling" />
<property name="cache" value="true" />
</bean>

<int-jms:inbound-gateway
request-destination-name="anotherQueue"
request-channel="inboundOrderingBillingJms"
destination-resolver="jndiDestinationResolver"
connection-factory="jndiObjectFactoryBeanBilling" />

<int:channel id="inboundOrderingBillingJms" /> <!-- handled by OrderingBillingInboundEndpoint -->

<context:component-scan base-package="com.att.ordering.endpoints.jms" />
<context:annotation-config />
<context:spring-configured />
<int:annotation-config />

</beans>

applicationContext-ordering-inbound-jms.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans ...">

<context:annotation-config />
<context:spring-configured />
<int:annotation-config />

<context:component-scan base-package="com.att.ordering.endpoints.jms"/>

</beans>

ServiceActivator 类:

package com.att.ordering.endpoints.jms;

import javax.xml.bind.JAXBElement;

import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderingBillingInboundEndpoint
{
@ServiceActivator(inputChannel = "inboundOrderingBillingJms")
//public void handleMessage(JAXBElement<String> accountNumber)
public void handleMessage(String accountNumber)
{
System.out.println("In OrderingBillingInboundEndpoint.handleMessage - accountNumber=" + accountNumber);
}
}

我用 WAR 引导 spring; WEB-INF/web.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
<param-name>parentContextKey</param-name>
<param-value>ordering-spring-bootstrap.war.context</param-value>
</context-param>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</context-param>

</web-app>

WEB-INF/classes/beanRefContext.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="ordering-spring-bootstrap.war.context"
class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list>
<value>/applicationContext-ordering-inbound-jms-spring-integration.xml</value>
<value>/applicationContext-ordering-inbound-jms.xml</value>
</list>
</constructor-arg>
</bean>
</beans>

在 ARTEM 初始回复后添加以下内容

我的 JNDI 名称是 java:jboss/exported/jms/queue/anotherQueue。它绑定(bind)到HornetQQueue[anotherQueue]

以下在 JBoss 中显示 - 注意:有 2 个 JNDI 条目;我正在使用第二个: enter image description here

这是正确的 - 我能够得到一个 Java JMS 程序(没有 Spring Integration),如下所示:

final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "remote://localhost:4447");
env.put(Context.SECURITY_PRINCIPAL, "appuser");
env.put(Context.SECURITY_CREDENTIALS, "appuser1!");
context = new InitialContext(env);

// JNDI name in JBoss is: java:jboss/exported/jms/queue/anotherQueue
connectionFactory = (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");
destination = (Destination) context.lookup("jms/queue/anotherQueue");
connection = connectionFactory.createConnection("appuser", "appuser1!");
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(destination);
consumer.setMessageListener(new MyListener());
connection.start();

我现在正在尝试使用 Spring Integration 获得相同的简单示例。

问题:

(A) 我应该将用户 ID 和密码放在哪里?

(B) 以下说法正确吗?如果不是,具体应该是什么?

<bean id="jndiTemplateBilling" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jboss.as.naming.InitialContextFactory</prop>
<prop key="java.naming.provider.url">remote://localhost:4447</prop>
</props>
</property>
</bean>

(C) 我应该如何更改以下内容?我删除了 proxyInterfaces;还有什么应该改变的?我不知道如何使用 jee:jndi-lookup

<bean id="jndiObjectFactoryBeanBilling" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplateBilling" />
<property name="jndiName" value="java:jboss/exported/jms/queue/anotherQueue" />
<property name="lookupOnStartup" value="false" />
</bean>

(D) 以下内容保持不变吗?

<bean id="jndiDestinationResolver"
class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplateBilling" />
<property name="cache" value="true" />
</bean>

(E) 以下内容是否发生变化?

<int-jms:inbound-gateway
request-destination-name="anotherQueue"
request-channel="inboundOrderingBillingJms"
destination-resolver="jndiDestinationResolver"
connection-factory="jndiObjectFactoryBeanBilling" />

最佳答案

看起来您的 jndiObjectFactoryBeanBilling bean 定义有误。这是为了

<property name="jndiName" value="java:jboss/exported/jms/queue/anotherQueue" />

日志确认的内容:

on target [HornetQQueue[anotherQueue]];

但它确实必须用于 javax.jms.ConnectionFactory:

connection-factory="jndiObjectFactoryBeanBilling" 

因此,只需尝试将 JNDI 名称更改为正确的名称即可。

从另一方面来说,我从未对 JBOSS JNDI 资源使用过所有这些 proxyInterfaces 选项。它们按原样工作良好,例如:

<jee:jndi-lookup id="jndiMqConnectionFactory" jndi-name="${mqConnectionFactory}"/>

<jee:jndi-lookup id="auditQueue" jndi-name="queue/AuditQueue"/>

关于java - Spring Integration 入站 JMS 与 JBoss createConnection() : IllegalArgumentException: ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32513726/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com