将 Spring 的 JndiObjectFactoryBean 转换为用于 Solace

编程入门 行业动态 更新时间:2024-10-25 06:31:06
本文介绍了将 Spring 的 JndiObjectFactoryBean 转换为用于 Solace-MQ JMS 的 ConnectionFactory 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个很好的工作 XML 配置,用于使用 JNDI 和 Spring 的 Camel 上下文

I have a good working XML configuration for Camel Context that uses JNDI with Spring

后来 Solace.JndiObjectFactoryBean 被用作 connectionFactory

Later Solace.JndiObjectFactoryBean gets used as 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(),我得到一个编译时异常:

I am trying to convert this into a Java class that extends from org.apache.camel.spring.javaconfig.CamelConfiguration. But there is one problem. When I try to set a connection factory on JMS component component.setConnectionFactory(getJndiObjectFactoryBean()); getJndiObjectFactoryBean(), I get a compile time exception :

The method setConnectionFactory(ConnectionFactory) in the type JmsComponent 
is not applicable for the arguments (JndiObjectFactoryBean)

但是当我尝试将从 getJndiObjectFactoryBean 显式返回的 JndiObjectFactoryBean 强制转换为 SolConnectionFactory 时,出现运行时错误

But when I try to cast JndiObjectFactoryBean returned from getJndiObjectFactoryBean explicitly to SolConnectionFactory, I get a runtime error

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.camelponent.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

I believe do have have requisite jars in the class path. sol-common-x.y.z.jar, sol-jcsmp-x.y.z.jar, sol-jms-x.y.z.jar

推荐答案

JndiObjectFactoryBean 不能转换成 ConnectionFactory.

有两种选择:

在您的 getJndiObjectFactoryBean() 方法返回的 JndiObjectFactoryBean 中使用 JndiObjectFactoryBean.getObject().

让 Spring 提供 ConnectionFactory. Use JndiObjectFactoryBean.getObject() in the JndiObjectFactoryBean that's returned by your getJndiObjectFactoryBean() method.

Get Spring to provide the ConnectionFactory.

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("config.xml");ConnectionFactory connectionFactory = (ConnectionFactory) context.getBean("Solace.JndiObjectFactoryBean");

这篇关于将 Spring 的 JndiObjectFactoryBean 转换为用于 Solace-MQ JMS 的 ConnectionFactory 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-19 22:09:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/971471.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   Spring   JndiObjectFactoryBean   Solace

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!