title: Why the Spring needs a @Bean on Converter and ClassMapper if I'm setting them directly on RabbitTemplate?
body: <p>I would like to understand why I need to mark the <code>getMessageConverter</code> and <code>classMapper</code> methods with <code>@Bean</code> even setting them directly in my custom RabbiteTemplate.</p>
  
  <p>Without the <code>@Bean</code> and passing them to <code>private</code>, the message not contains the <code>TypeId</code> correctly in the message.</p>
  
  <p>So, with the @Bean and public methods, I had the correct header on the message:</p>
  
  <pre><code>headers: __TypeId__:    OrderProducer
  </code></pre>
  
  <p>Without them, the message contains the incorrect TypeId:</p>
  
  <pre><code>headers: __TypeId__:    com.projet.order.message.OrderProducer
  </code></pre>
  
  <p>What is the default behavior without the classMapper. </p>
  
  <p>See the code:</p>
  
  <pre><code>@Bean(name = "sendCommandOrderCreate")
  public RabbitTemplate sendCommandOrderCreate() {
      RabbitTemplate rabbitTemplate = createRabbitTemplate(getMessageConverter());
      rabbitTemplate.setExchange("order.exchange");
      rabbitTemplate.setRoutingKey("order.cmd.create");
      return rabbitTemplate;
  }
  
  private RabbitTemplate createRabbitTemplate(final MessageConverter messageConverter) {
      final RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
      rabbitTemplate.setMessageConverter(messageConverter);
      return rabbitTemplate;
  }
  
  @Bean
  public Jackson2JsonMessageConverter getMessageConverter() {
      Jackson2JsonMessageConverter jackson2JsonMessageConverter = new Jackson2JsonMessageConverter();
      jackson2JsonMessageConverter.setClassMapper(classMapper());
      return jackson2JsonMessageConverter;
  }
  
  @Bean
  public DefaultClassMapper classMapper() {
      DefaultClassMapper classMapper = new DefaultClassMapper();
      Map&lt;String, Class&lt;?&gt;&gt; idClassMapping = new HashMap&lt;&gt;();
      idClassMapping.put(OrderProducer.class.getSimpleName(), OrderProducer.class);
      idClassMapping.put(OrderConsumer.class.getSimpleName(), OrderConsumer.class);
      classMapper.setIdClassMapping(idClassMapping);
      return classMapper;
  }
  </code></pre>
  
  <p>And how I'm injecting the bean in a Service:</p>
  
  <pre><code>public OrderService(@Qualifier("sendCommandOrderCreate") RabbitTemplate rabbitTemplate) {
      this.rabbitTemplate = rabbitTemplate;
  }
  </code></pre>