Skip to content

Commit aa0d91d

Browse files
authored
GH-4110: AVRO related AOT reflection
Fixes #4110 Refactor `KafkaAvroBeanRegistrationAotProcessor` to use `BindingReflectionHintsRegistrar` Replace manual reflection hints registration with `BindingReflectionHintsRegistrar` to simplify AVRO type reflection configuration in AOT processing. Adding `org.apache.kafka.common.security.oauthbearer.DefaultJwtRetriever` to Kafka runtime hints. Signed-off-by: Soby Chacko <[email protected]>
1 parent c102814 commit aa0d91d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

spring-kafka/src/main/java/org/springframework/kafka/aot/KafkaAvroBeanRegistrationAotProcessor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.apache.kafka.clients.consumer.ConsumerRecords;
2727
import org.jspecify.annotations.Nullable;
2828

29-
import org.springframework.aot.hint.MemberCategory;
29+
import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
3030
import org.springframework.aot.hint.ReflectionHints;
3131
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
3232
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
@@ -42,6 +42,7 @@
4242
*
4343
* @author Gary Russell
4444
* @author Sagnhyeok An
45+
* @author Soby Chacko
4546
* @since 3.0
4647
*
4748
*/
@@ -55,6 +56,8 @@ public class KafkaAvroBeanRegistrationAotProcessor implements BeanRegistrationAo
5556

5657
private static final boolean AVRO_PRESENT = ClassUtils.isPresent(AVRO_GENERATED_CLASS_NAME, null);
5758

59+
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
60+
5861
@Override
5962
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
6063
if (!AVRO_PRESENT) {
@@ -83,9 +86,7 @@ public class KafkaAvroBeanRegistrationAotProcessor implements BeanRegistrationAo
8386
if (!avroTypes.isEmpty()) {
8487
return (generationContext, beanRegistrationCode) -> {
8588
ReflectionHints reflectionHints = generationContext.getRuntimeHints().reflection();
86-
avroTypes.forEach(type -> reflectionHints.registerType(type,
87-
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
88-
MemberCategory.INVOKE_PUBLIC_METHODS)));
89+
this.bindingRegistrar.registerReflectionHints(reflectionHints, avroTypes.toArray(new Class<?>[0]));
8990
};
9091
}
9192
return null;

spring-kafka/src/main/java/org/springframework/kafka/aot/KafkaRuntimeHints.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.apache.kafka.clients.producer.Producer;
2525
import org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic;
2626
import org.apache.kafka.common.protocol.Message;
27+
import org.apache.kafka.common.security.oauthbearer.DefaultJwtRetriever;
2728
import org.apache.kafka.common.serialization.Serdes;
2829
import org.apache.kafka.common.utils.AppInfoParser.AppInfo;
2930
import org.apache.kafka.common.utils.ImplicitLinkedHashCollection;
@@ -87,6 +88,8 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
8788
builder -> builder.withMembers(MemberCategory.INVOKE_DECLARED_METHODS)));
8889

8990
Stream.of(
91+
// Following Kafka classes need to be ideally part of Oracle's reachability metadata repository.
92+
DefaultJwtRetriever.class,
9093
Message.class,
9194
ImplicitLinkedHashCollection.Element.class,
9295
NewTopic.class,

0 commit comments

Comments
 (0)