Skip to content

Commit 67bd8cf

Browse files
authored
GH-3242: Clarify docs on custom Consumer/Producer factories
Fixes: #3242 **Auto-cherry-pick to `3.1.x`**
1 parent 35d26e1 commit 67bd8cf

File tree

1 file changed

+5
-2
lines changed
  • spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka

1 file changed

+5
-2
lines changed

spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/serdes.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ The following Spring Boot example overrides the default factories:
166166
[source, java]
167167
----
168168
@Bean
169-
public ConsumerFactory<String, Thing> kafkaConsumerFactory(JsonDeserializer customValueDeserializer) {
169+
public ConsumerFactory<?, ?> kafkaConsumerFactory(JsonDeserializer customValueDeserializer) {
170170
Map<String, Object> properties = new HashMap<>();
171171
// properties.put(..., ...)
172172
// ...
@@ -175,7 +175,7 @@ public ConsumerFactory<String, Thing> kafkaConsumerFactory(JsonDeserializer cust
175175
}
176176
177177
@Bean
178-
public ProducerFactory<String, Thing> kafkaProducerFactory(JsonSerializer customValueSerializer) {
178+
public ProducerFactory<?, ?> kafkaProducerFactory(JsonSerializer customValueSerializer) {
179179
return new DefaultKafkaProducerFactory<>(properties.buildProducerProperties(),
180180
new StringSerializer(), customValueSerializer);
181181
}
@@ -185,6 +185,9 @@ public ProducerFactory<String, Thing> kafkaProducerFactory(JsonSerializer custom
185185
Setters are also provided, as an alternative to using these constructors.
186186
====
187187

188+
NOTE: When using Spring Boot and overriding the `ConsumerFactory` and `ProducerFactory` as shown above, wild card generic types need to be used with the bean method return type.
189+
If concrete generic types are provided instead, then Spring Boot will ignore these beans and still use the default ones.
190+
188191
Starting with version 2.2, you can explicitly configure the deserializer to use the supplied target type and ignore type information in headers by using one of the overloaded constructors that have a boolean `useHeadersIfPresent` argument (which is `true` by default).
189192
The following example shows how to do so:
190193

0 commit comments

Comments
 (0)