Results 1 to 2 of 2

Thread: Spring TypeMismatchException Bug?

  1. #1
    Join Date
    Sep 2005
    Posts
    16

    Default Spring TypeMismatchException Bug?

    I am getting a TypeMismatchException which doesn't seem to make any sense. I am setting a org.springframework.jms.core.JmsTemplate property in a Message-driven Bean that I created with a org.springframework.jms.core.JmsTemplate from my applicationConfiguration.xml file. The error is shown below:

    13:42:35,763 ERROR [[/search]] Servlet /search threw load() exception
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'mdb1' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptions Exception: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.jms.core.JmsTemplate] to required type [org.springframework.jms.core.JmsTemplate] for property 'jmsTemplate']
    PropertyAccessExceptionsException (1 errors)
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.jms.core.JmsTemplate] to required type [org.springframework.jms.core.JmsTemplate] for property 'jmsTemplate'
    at org.springframework.beans.BeanWrapperImpl.doTypeCo nversionIfNecessary(BeanWrapperImpl.java:1035)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:803)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:716)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValue(BeanWrapperImpl.java:844)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:871)
    at org.springframework.beans.BeanWrapperImpl.setPrope rtyValues(BeanWrapperImpl.java:860)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:926)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:727)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:336)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:223)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)

    Here is a piece of my configuration file:
    <bean id="jmsXAConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName">
    <value>java:/JmsXA</value>
    </property>
    </bean>
    <bean id="deliveryModePersistent" class="org.springframework.beans.factory.config.Fi eldRetrievingFactoryBean">
    <property name="staticField">
    <value>javax.jms.DeliveryMode.PERSISTENT</value>
    </property>
    </bean>
    <bean id="jmsTemplate2" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory"><ref bean="jmsXAConnectionFactory"/></property>
    <property name="defaultDestination"><ref bean="queue2"/></property>
    <property name="deliveryMode"><ref bean="deliveryModePersistent"/></property>
    <property name="priority"><value>4</value></property>
    <property name="timeToLive"><value>0</value></property>
    <property name="explicitQosEnabled"><value>true</value></property>
    </bean>
    <bean id="mdb1" class="uk.ident1.prototype.mdb1.MDB1Bean">
    <property name="jmsTemplate"><ref bean="jmsTemplate2"/></property>
    </bean>

    Here is the code for my MDB:
    package uk.ident1.prototype.mdb1;



    import java.util.logging.Level;

    import java.util.logging.Logger;



    import javax.jms.Connection;

    import javax.jms.ConnectionFactory;

    import javax.jms.DeliveryMode;

    import javax.jms.Destination;

    import javax.jms.JMSException;

    import javax.jms.MessageListener;

    import javax.jms.Message;

    import javax.jms.MessageProducer;

    import javax.jms.ObjectMessage;

    import javax.jms.Session;

    import javax.naming.InitialContext;

    import javax.ejb.MessageDrivenBean;

    import javax.ejb.MessageDrivenContext;



    import org.springframework.context.access.ContextSingleto nBeanFactoryLocator;

    import org.springframework.context.support.ClassPathXmlAp plicationContext;

    import org.springframework.ejb.support.AbstractJmsMessage DrivenBean;

    import org.springframework.jms.core.JmsTemplate;



    import uk.ident1.prototype.db.PrototypeDataAccessHibernat eImpl;

    import uk.ident1.prototype.sei.Demographics;



    public class MDB1Bean extends AbstractJmsMessageDrivenBean implements MessageListener

    {

    private static Logger log = Logger.getLogger(MDB1Bean.class.getName());

    private PrototypeDataAccessHibernateImpl da = null;

    private JmsTemplate jmsTemplate = null;



    protected void onEjbCreate()

    {

    da = (PrototypeDataAccessHibernateImpl)getBeanFactory() .getBean("umTarget");

    jmsTemplate = (JmsTemplate)getBeanFactory().getBean("jmsTemplate 2");

    }



    public void setDataAccess(PrototypeDataAccessHibernateImpl da)

    {

    this.da = da;

    }



    /**

    * Sets the Spring jmsTemplate to integrate the MDB with the Spring Framework

    * @param jmsTemplate

    */

    public void setJmsTemplate(JmsTemplate jmsTemplate)

    {

    this.jmsTemplate = jmsTemplate;

    }



    public void onMessage(Message m)

    {

    ObjectMessage idMsg = (ObjectMessage) m;

    try

    {

    Long l = (Long)idMsg.getObject();

    Demographics d = da.getDemographic(new Integer(l.intValue()));

    log.info("Received message containing id: " + d.getId());

    log.info(d.toString());

    jmsTemplate.convertAndSend(l);

    }

    catch (Exception e)

    {

    log.log(Level.SEVERE, "onMessage(): failed to process message!", e);

    }

    }

    }

    Is this a bug or am I doing something wrong? If so, does anyone have any suggestions on how to fix this?

    Thanks in advanced!

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    It looks like you have two versions of the JMS classes on your classpath - most likely a jms.jar in your WAR file.

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 5
    Last Post: Aug 9th, 2008, 05:30 AM
  3. A Spring Class Loader?
    By azzoti in forum Architecture
    Replies: 8
    Last Post: May 7th, 2005, 04:02 AM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Replies: 2
    Last Post: Jan 21st, 2005, 04:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •