Skip to content

Commit abf320d

Browse files
committed
Register reflection hints for SslBundleSslEngineFactory
Closes gh-44435
1 parent 453002b commit abf320d

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfiguration.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,9 @@
2424
import org.apache.kafka.clients.consumer.ConsumerConfig;
2525
import org.apache.kafka.clients.producer.ProducerConfig;
2626

27+
import org.springframework.aot.hint.MemberCategory;
28+
import org.springframework.aot.hint.RuntimeHints;
29+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
2730
import org.springframework.beans.factory.ObjectProvider;
2831
import org.springframework.boot.autoconfigure.AutoConfiguration;
2932
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -38,6 +41,7 @@
3841
import org.springframework.boot.ssl.SslBundles;
3942
import org.springframework.context.annotation.Bean;
4043
import org.springframework.context.annotation.Import;
44+
import org.springframework.context.annotation.ImportRuntimeHints;
4145
import org.springframework.kafka.core.ConsumerFactory;
4246
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
4347
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
@@ -73,6 +77,7 @@
7377
@ConditionalOnClass(KafkaTemplate.class)
7478
@EnableConfigurationProperties(KafkaProperties.class)
7579
@Import({ KafkaAnnotationDrivenConfiguration.class, KafkaStreamsAnnotationDrivenConfiguration.class })
80+
@ImportRuntimeHints(KafkaAutoConfiguration.KafkaRuntimeHints.class)
7681
public class KafkaAutoConfiguration {
7782

7883
private final KafkaProperties properties;
@@ -230,4 +235,13 @@ private static void setBackOffPolicy(RetryTopicConfigurationBuilder builder, Top
230235
}
231236
}
232237

238+
static class KafkaRuntimeHints implements RuntimeHintsRegistrar {
239+
240+
@Override
241+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
242+
hints.reflection().registerType(SslBundleSslEngineFactory.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
243+
}
244+
245+
}
246+
233247
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/kafka/KafkaAutoConfigurationTests.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2024 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,6 +45,9 @@
4545
import org.junit.jupiter.params.ParameterizedTest;
4646
import org.junit.jupiter.params.provider.ValueSource;
4747

48+
import org.springframework.aot.hint.MemberCategory;
49+
import org.springframework.aot.hint.RuntimeHints;
50+
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
4851
import org.springframework.boot.autoconfigure.AutoConfigurations;
4952
import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration;
5053
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
@@ -856,6 +859,15 @@ void specificSecurityProtocolOverridesCommonSecurityProtocol() {
856859
});
857860
}
858861

862+
@Test
863+
void shouldRegisterRuntimeHints() {
864+
RuntimeHints runtimeHints = new RuntimeHints();
865+
new KafkaAutoConfiguration.KafkaRuntimeHints().registerHints(runtimeHints, getClass().getClassLoader());
866+
assertThat(RuntimeHintsPredicates.reflection()
867+
.onType(SslBundleSslEngineFactory.class)
868+
.withMemberCategories(MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)).accepts(runtimeHints);
869+
}
870+
859871
private KafkaConnectionDetails kafkaConnectionDetails() {
860872
return new KafkaConnectionDetails() {
861873

0 commit comments

Comments
 (0)