gpt4 book ai didi

jms - 将 Spring 的 JndiObjectFactoryBean 转换为用于 Solace-MQ JMS 的 ConnectionFactory 时出错

转载 作者:行者123 更新时间:2023-12-01 11:28:20 33 4
gpt4 key购买 nike

我对 Camel Context 有一个很好的工作 XML 配置,它使用 JNDI 和 Spring








后来 Solace.JndiObjectFactoryBean 被用作 connectionFactory

<bean id="Solace.JmsComponent" class="  on">
<property name="connectionFactory" ref="Solace.JndiObjectFactoryBean" />
<property name="destinationResolver" ref="Solace.JndiDestinationResolver" />
</bean>

我正在尝试将其转换为从 org.apache.camel.spring.javaconfig.CamelConfiguration 扩展的 Java 类.但是有一个问题。当我尝试在 JMS 组件上设置连接工厂时
component.setConnectionFactory(getJndiObjectFactoryBean()); getJndiObjectFactoryBean(),
我得到一个编译时异常:
The method setConnectionFactory(ConnectionFactory) in the type JmsComponent 
is not applicable for the arguments (JndiObjectFactoryBean)

但是,当我尝试将从 getJndiObjectFactoryBean 显式返回的 JndiObjectFactoryBean 强制转换为 SolConnectionFactory 时,出现运行时错误
016-02-05 17:39:09,234|[localhost-startStop-1]|[]|[]|[ERROR] web.context.ContextLoader [line:307] Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getJMSConfiguration' defined in class path resource [com//camel
/CamelRoutesConfig.class]: Instantiation of bean failed; nested exception is org
.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.apache.camel.component.jms.JmsConfiguration com.camel.CamelRoutesConfig.getJMSConfiguration()] threw exception; nested exception is java.lang.ClassCastException: org.springframework.jndi.JndiObjectFactoryBean$$EnhancerByCG
LIB$$18b94f95 cannot be cast to com.solacesystems.jms.SolConnectionFactory
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsi
ngFactoryMethod(ConstructorResolver.java:581)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1029)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory
.createBeanInstance(AbstractAutowireCapableBeanFactory.java:925)

我相信在类路径中确实有必要的 jars。 sol-common-x.y.z.jar, sol-jcsmp-x.y.z.jar, sol-jms-x.y.z.jar

最佳答案

一个 JndiObjectFactoryBean不能铸成 ConnectionFactory .

有两种选择:

  • 使用 JndiObjectFactoryBean.getObject()JndiObjectFactoryBean这是由您的 getJndiObjectFactoryBean() 返回的方法。
  • 获取 Spring 提供的 ConnectionFactory .
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
    ConnectionFactory connectionFactory = (ConnectionFactory) context.getBean("Solace.JndiObjectFactoryBean");
  • 关于jms - 将 Spring 的 JndiObjectFactoryBean 转换为用于 Solace-MQ JMS 的 ConnectionFactory 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35298732/

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