title: MessageConversionException: Failed to resolve class name in Spring AMQP
body: <p>I am trying out simple sender and receiving of messages using Spring AMQP with <code>jackson2JsonMessageConverter</code>.
  Also, what is the significance of <code>_TypeId_</code> here
  why it is showing sender package with class name?
  I am facing issues in receiving the message.</p>
  
  <p>Below is my configuration</p>
  
  <blockquote>
    <p>org.springframework.amqp.support.converter.MessageConversionException:
    failed to resolve class name. Class not found
    [org.springframework.amqp.helloworld.User]
                at org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.getClassIdType(DefaultJackson2JavaTypeMapper.java:121)
                at org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.toJavaType(DefaultJackson2JavaTypeMapper.java:90)
                at org.springframework.amqp.support.converter.Jackson2JsonMessageConverter.fromMessage(Jackson2JsonMessageConverter.java:145)
                at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.extractMessage(AbstractAdaptableMessageListener.java:236)
                at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:288)
                at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:777)
                ... 10 common frames omitted Caused by: java.lang.ClassNotFoundException:
    org.springframework.amqp.helloworld.User
                at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
                at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1139)
                at org.springframework.util.ClassUtils.forName(ClassUtils.java:250)
                at org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.getClassIdType(DefaultJackson2JavaTypeMapper.java:118)
                ... 15 common frames omitted</p>
  </blockquote>
  
  <p>XML Configuration</p>
  
  <pre><code>            &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
              xmlns:context="http://www.springframework.org/schema/context"
              xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
              xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
              xmlns:rabbit="http://www.springframework.org/schema/rabbit"
              xsi:schemaLocation="http://www.springframework.org/schema/rabbit
               http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
               http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
               http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
               http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd  
               http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd  
               http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
               http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"&gt;
  
  
              &lt;rabbit:connection-factory id="connectionFactory"
                          channel-cache-size="25" host="10.165.18.29" username="BipUser"
                          password="bip" /&gt;
  
              &lt;rabbit:queue name="Job Queue"&gt;&lt;/rabbit:queue&gt;
  
              &lt;rabbit:queue name="Input Queue"&gt;&lt;/rabbit:queue&gt;
  
              &lt;rabbit:queue name="More Info Queue"&gt;&lt;/rabbit:queue&gt;
  
              &lt;rabbit:queue name="Adaptor O/P Queue"&gt;&lt;/rabbit:queue&gt;
  
              &lt;rabbit:queue name="Command Queue"&gt;&lt;/rabbit:queue&gt;
  
              &lt;rabbit:queue name="Error Queue"&gt;&lt;/rabbit:queue&gt;
  
              &lt;bean id="simpleMessageConverter"
                          class="org.springframework.amqp.support.converter.Jackson2JsonMessageConverter"&gt;
              &lt;/bean&gt;
  
              &lt;rabbit:template id="amqpTemplate" connection-factory="connectionFactory"
                          message-converter="jsonConverterWithDefaultType" /&gt;
  
              &lt;rabbit:listener-container
                          connection-factory="connectionFactory" auto-declare="true"
                          message-converter="simpleMessageConverter" auto-startup="true"
                          acknowledge="auto"&gt;
                          &lt;rabbit:listener ref="rabbitMQJobListener"
                                      queue-names="Job Queue" priority="10" /&gt;
  
              &lt;/rabbit:listener-container&gt;
  
              &lt;rabbit:admin connection-factory="connectionFactory" id="amqpAdmin" /&gt;
  
              &lt;bean id="rabbitMQJobListener" class="com.bosch.bip.rabbitmq.consumer.RabbitMQJobListener"&gt;
              &lt;/bean&gt;
  
              &lt;rabbit:annotation-driven container-factory="rabbitListenerContainerFactory" /&gt;
  
              &lt;bean id="rabbitListenerContainerFactory"
                          class="org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory"&gt;
                          &lt;property name="connectionFactory" ref="connectionFactory"&gt;&lt;/property&gt;
                          &lt;property name="messageConverter" ref="jsonConverterWithDefaultType"&gt;&lt;/property&gt;
              &lt;/bean&gt;
  
              &lt;bean id="jsonConverterWithDefaultType"
                          class="org.springframework.amqp.support.converter.Jackson2JsonMessageConverter"&gt;
                          &lt;property name="classMapper"&gt;
                                      &lt;bean class="org.springframework.amqp.support.converter.DefaultClassMapper"&gt;
                                      &lt;/bean&gt;
                          &lt;/property&gt;
              &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Sender</p>
  
  <pre><code>package org.springframework.amqp.helloworld;
  
  import org.springframework.amqp.core.Message;
  import org.springframework.amqp.core.MessageProperties;
  import org.springframework.amqp.rabbit.core.RabbitTemplate;
  import org.springframework.amqp.support.converter.DefaultClassMapper;
  import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.ApplicationContext;
  import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  import org.springframework.stereotype.Component;
  
  @Component
  public class Sender {
  
  
              public static void main(String[] args) {
  
                          ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfiguration.class);
                          User user=new User();
                          user.setPassword("welcome");
                          user.setUserName("welcome");
                          user.setXml("myxml");
                          RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);
  
                          Jackson2JsonMessageConverter converter = context.getBean(Jackson2JsonMessageConverter.class);
                          MessageProperties properties = new MessageProperties();
                          properties.setHeader("user", "user");
                          properties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
                          Message message = converter.toMessage(user, properties);
  
                          System.out.println(message);
  
  
  
                          rabbitTemplate.send(message);
              }
  
              /* @RabbitListener(queues = HelloWorldConfiguration.helloWorldQueueName)
                public void handleMessage(User user) {
                 System.out.println("User Values::::::::"+user.getPassword());
                }*/
  }
  </code></pre>
  
  <p>Consumer</p>
  
  <pre><code>package com.bip.rabbitmq.consumer;
  
  import org.springframework.amqp.rabbit.annotation.EnableRabbit;
  import org.springframework.amqp.rabbit.annotation.RabbitListener;
  import org.springframework.stereotype.Component;
  
  import com.bip.entity.User;
  
  @EnableRabbit
  @Component
  public class RabbitMQJobListener {
  
  
              @RabbitListener(queues="Job Queue")
              public void onMessage(User message) {
                          System.out.println(new String(message.getPassword()));
  
              }
  }
  </code></pre>
  
  <p>RabbitMQ</p>
  
  <pre><code>Exchange    (AMQP default)
  Routing Key Job Queue
  Redelivered ○
  Properties  
  priority:   0
  delivery_mode:  2
  headers:    
  user:   user
  __TypeId__: org.springframework.amqp.helloworld.User
  content_encoding:   UTF-8
  content_type:   application/json
  Payload
  57 bytes
  Encoding: string
  {"userName":"welcome","password":"welcome","xml":"myxml"}
  </code></pre>