The spring-boot-starter-kafka dependency is the Spring Boot 4 starter for Apache Kafka. It brings in Spring for Apache Kafka (spring-kafka) and the Kafka client, and auto-configures a KafkaTemplate for sending and listener containers for @KafkaListener methods from your spring.kafka.* properties.
In Spring Boot 3.x there was no starter with this name: you added org.springframework.kafka:spring-kafka directly and Boot auto-configured it. The Boot 4 modular starter is a convenience wrapper over the same functionality.
| Piece | Role |
|---|---|
| Spring for Apache Kafka | KafkaTemplate, @KafkaListener, error handling, retry topics, transactions |
| Apache Kafka client | Producer and consumer implementations |
| Auto-configuration | Producer and consumer factories, listener container factory, KafkaAdmin |
On Spring Boot 3.x, use this instead:
Versions are managed by Spring Boot, so you leave them out.
bootstrap-servers is set once at the top level and applies to producers, consumers and the admin client. Consumer-only settings such as group-id belong under consumer.
Setting acks: all makes the broker confirm a write only after all in-sync replicas have it. Restrict spring.json.trusted.packages to your own packages instead of using *, which allows deserialization of arbitrary types.
send is asynchronous and returns a CompletableFuture. In Spring Kafka 3 and later it replaced the older ListenableFuture. Using the order id as the key keeps all events for one order in the same partition, which preserves their order.
Consumers in the same group share the topic's partitions, so running more instances increases throughput up to the number of partitions. Delivery is at least once by default, so make handlers idempotent.
Declare topics as beans so KafkaAdmin creates them at startup if they do not exist:
For failures, the default error handler retries a record a few times and then logs it. For production, configure a DefaultErrorHandler with a DeadLetterPublishingRecoverer so poison messages move to a dead-letter topic, or use @RetryableTopic for non-blocking retries.
@EmbeddedKafka from spring-kafka-test starts an in-process broker for tests.The starter wraps spring-kafka for Spring Boot 4. On Boot 3.x you depend on spring-kafka directly. Auto-configuration behaves the same.
Kafka tracks offsets per group. Without one the consumer cannot join a group, and the listener will not start unless you configure a group id.
Use JsonSerializer and JsonDeserializer as shown above, or a schema registry with Avro or Protobuf for contracts that must evolve safely.
Not by default. You can enable Kafka transactions for exactly-once semantics between topics, but side effects outside Kafka still need idempotent handling.
spring-boot-starter-kafka adds Spring for Apache Kafka to a Spring Boot 4 application and configures producers, consumers and topics from spring.kafka.* properties. Use KafkaTemplate to publish and @KafkaListener to consume, key messages for ordering, make handlers idempotent, and add a dead-letter strategy before going to production.