对于使用JNDI和Spring
的Camel Context,我有一个很好的XML配置
稍后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)
我相信在课程路径中有必要的罐子。 sol-common-x.y.z.jar,sol-jcsmp-x.y.z.jar,sol-jms-x.y.z.jar
答案 0 :(得分:3)
JndiObjectFactoryBean
无法投放到ConnectionFactory
。
有两种选择:
JndiObjectFactoryBean.getObject()
方法返回的JndiObjectFactoryBean
中使用getJndiObjectFactoryBean()
。让Spring提供ConnectionFactory
。
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("config.xml");
ConnectionFactory connectionFactory = (ConnectionFactory) context.getBean("Solace.JndiObjectFactoryBean");
答案 1 :(得分:0)
当将一个有效的Spring XML配置(由Apache Camel用于从Weblogic JMS服务器队列读取)移植到Spring-Boot偏好的Java配置时,我们遇到了类似的情况。
jmsConfiguration.setConnectionFactory( (javax.jms.ConnectionFactory)getJndiFactoryBean().getObject());
上面的代码可以模仿
<bean id="jmsConfiguration" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jndiFactoryBean"/>
<property name="destinationResolver" ref="jndiDestinationResolver"/>
</bean>
(不清楚Spring XML在封面下做了多少额外的事情,因为它并不像在jndiFactoryBean
上设置jmsConfiguration
那么简单
答案 2 :(得分:0)
如果您使用getObject()方法,请确保在使用getObject()之前调用afterPropertiesSet()
def get_sorted_items():
return Item.objects.all().annotate(
first=Attribute.objects.filter(key='first').values('value'),
second=Attribute.objects.filter(key='second').values('value'),
).order_by('first', 'second')