You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-kafka-docs/src/main/antora/modules/ROOT/pages/kafka/serdes.adoc
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -166,7 +166,7 @@ The following Spring Boot example overrides the default factories:
166
166
[source, java]
167
167
----
168
168
@Bean
169
-
public ConsumerFactory<String, Thing> kafkaConsumerFactory(JsonDeserializer customValueDeserializer) {
169
+
public ConsumerFactory<?, ?> kafkaConsumerFactory(JsonDeserializer customValueDeserializer) {
170
170
Map<String, Object> properties = new HashMap<>();
171
171
// properties.put(..., ...)
172
172
// ...
@@ -175,7 +175,7 @@ public ConsumerFactory<String, Thing> kafkaConsumerFactory(JsonDeserializer cust
175
175
}
176
176
177
177
@Bean
178
-
public ProducerFactory<String, Thing> kafkaProducerFactory(JsonSerializer customValueSerializer) {
178
+
public ProducerFactory<?, ?> kafkaProducerFactory(JsonSerializer customValueSerializer) {
179
179
return new DefaultKafkaProducerFactory<>(properties.buildProducerProperties(),
180
180
new StringSerializer(), customValueSerializer);
181
181
}
@@ -185,6 +185,9 @@ public ProducerFactory<String, Thing> kafkaProducerFactory(JsonSerializer custom
185
185
Setters are also provided, as an alternative to using these constructors.
186
186
====
187
187
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
+
188
191
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).
0 commit comments