MozenRath
MozenRath

Reputation: 10030

Spring ActiveMQ Issue

A bit Urgent please help!

Why do I get IllegalArgumentException Cannot convert value of type String to required type Product, in Spring?

I read this question already as I am getting a similar exception:

<Feb 13, 2012 11:55:39 AM IST> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationExceptio
n: Error creating bean with name 'jmsTemplate' defined in class path resource [manager-security-audit.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchExc
eption: Failed to convert property value of type [java.lang.String] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory'; nested exception is java.lang.IllegalArgumentExcept
ion: Cannot convert value of type [java.lang.String] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory': no matching editors or conversion strategy found.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsTemplate' defined in class path resource [manager-security-audit.xml]: Initialization of bean failed; nested
exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory
'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [javax.jms.ConnectionFactory] for property 'connectionFactory': no matching
editors or conversion strategy found
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
        Truncated. see log file for complete stacktrace

I have also seen the answer to that question and now the problem in my case is: How do I find out if I have a similar problem of defining a parameter(personally I don't think that is the issue here(just gut feeling))? OR Is this some other issue?

Please Help

Here is the xml file:

<?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:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/lang

http://www.springframework.org/schema/lang/spring-lang-2.0.xsd">
<bean id="auditListener" class="com.unica.manager.audit.AuditListener"/>
<bean id="auditEventDestination" class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg value="audit.event.queue"/>
</bean>
<bean id="auditEventMessageConverter" class="com.unica.manager.audit.AuditEventMessageConverter"/>

<bean id="purePojoMdp" class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
    <property name="delegate" ref="AuditEventManager"/>
    <property name="defaultListenerMethod" value="addAuditEvent"/>
    <property name="messageConverter" ref="auditEventMessageConverter"/>
</bean>
<bean name="auditListenerContainer"  class="org.springframework.jms.listener.SimpleMessageListenerContainer" lazy-init="true">
    <property name="autoStartup" value="false"/>
    <property name="connectionFactory" value=""/>
    <property name="destination" ref="auditEventDestination"/>
    <property name="messageListener" ref="purePojoMdp"/>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" depends-on="ConfigurationManager" >
    <property name="connectionFactory" value=""/>
    <property name="messageConverter" ref="auditEventMessageConverter"/>
</bean>
<bean id="audit" class="com.unica.manager.audit.Audit" >
    <property name="jmsTemplate" ref="jmsTemplate"/>
        <property name="enableQueuing" value="true"/>
        <property name="auditEventManager" ref="AuditEventManager"/>
    <property name="destination" ref="auditEventDestination"/>
</bean>

Upvotes: 1

Views: 12946

Answers (2)

Santosh
Santosh

Reputation: 17893

Please post your spring configuration details (the xml file). Right now only thing thats evident from the logs is that you are trying to inject the property connectionFactory as string. Please make sure that you define a bean with id connectionFactory and it should be of type javax.jms.ConnectionFactory and then use it to inject.

Please post the xml configuration. That will help further debug the issue.

EDIT:

Based on you input,

I don't see a bean defined as <property name="connectionFactory" ... anywhere. You also mention that its working on some other environment. Please check which xml file contains the definition of this bean and make sure that file is loaded by spring along with the xml you posted.

Upvotes: 1

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340723

Why aren't you injecting anything into connectionFactory property:

<property name="connectionFactory" value=""/>

This has to be changed into:

<property name="connectionFactory" ref="amqConnectionFactory"/>

connectionFactory property is of type javax.jms.ConnectionFactory (see: JmsAccessor.setConnectionFactory()).

amqConnectionFactory factory can be defined as follows:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:amq="http://activemq.apache.org/schema/core"
   xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

    <amq:connectionFactory id="amqConnectionFactory" brokerURL="vm://localhost" />

</beans>

Upvotes: 4

Related Questions