In Spring Boot, RabbitTemplate is the ready-made bean you inject to send messages to RabbitMQ. Boot auto-configures it when spring-boot-starter-amqp is on the classpath, wiring in a connection factory and your spring.rabbitmq.* settings, so you can publish a message with a single convertAndSend call.
It is a thin template over the Spring AMQP client: it converts Java objects to messages, publishes them to an exchange with a routing key, and supports confirms, returns and request/reply. Boot removes the manual setup, and this article shows what is configured for you.
Add the starter, and Boot creates these beans for you:
CachingConnectionFactory, built from the spring.rabbitmq.* properties.RabbitTemplate, configured from spring.rabbitmq.template.*.AmqpAdmin (a RabbitAdmin), which declares queues, exchanges and bindings that exist as beans.@RabbitListener.All of them back off if you define your own bean of the same type, so you can override just one piece.
For Gradle, use implementation 'org.springframework.boot:spring-boot-starter-amqp'.
Put the broker address and template defaults in application.yml:
The template.exchange and template.routing-key values become the defaults used by the short convertAndSend(obj) style overloads. The guest account only works from localhost on a stock RabbitMQ install, so create a real user for any other environment and keep the password in a secret store.
Declare the exchange, queue and binding as beans. RabbitAdmin creates them on the broker the first time a connection opens.
Then inject the template into a service:
OrderCreated can be a record. With the default converter it would have to implement Serializable, which is why the next section matters.
Out of the box, the template uses SimpleMessageConverter, which sends Strings and byte arrays as-is and everything else through Java serialization. Switch to JSON by declaring one MessageConverter bean; Boot applies it to the template and to listener containers automatically:
Spring AMQP releases built on Jackson 3 introduce JacksonJsonMessageConverter as the replacement name, so use the class that matches your Boot version.
The usual counterpart to the template is a listener. Boot starts the container for you:
If the listener throws, Boot's default behaviour is to requeue and retry, which can loop forever on a poison message. Configure spring.rabbitmq.listener.simple.retry.enabled=true or use a dead letter queue.
RabbitMQContainer with @ServiceConnection (Boot 3.1+) so connection properties are set automatically.publisher-returns and mandatory; an unroutable message is otherwise silently dropped.ConnectException on startup means the host, port or credentials are wrong, or the broker is not running yet.spring.rabbitmq.template.retry.enabled=true to retry publishing while the broker is briefly unavailable.No. Boot creates it from spring-boot-starter-amqp. Define your own RabbitTemplate bean only when you need something the properties cannot express.
Set spring.rabbitmq.template.exchange and spring.rabbitmq.template.routing-key, or pass them explicitly to convertAndSend.
Declare a Jackson2JsonMessageConverter bean (or the Jackson 3 equivalent in newer releases). Boot wires it into the template for you.
It can poll with receiveAndConvert, but regular consumption belongs to @RabbitListener.
Spring Boot auto-configures RabbitTemplate so you inject it and call convertAndSend. Set the broker and template defaults in spring.rabbitmq.*, declare queues and bindings as beans, use a JSON message converter, and turn on confirms and returns when delivery matters.