Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ba312f6

Browse files
committedNov 29, 2024·
Update AOT support after RuntimeHints changes
This commit adapts AOT support in various modules after the RuntimeHints and related deprecation changes. `MemberCategory.INTROSPECT_*` hints are now removed and `MemberCategory.*_FIELDS` are replaced with `MemberCategory.INVOKE*_FIELDS` when invocation is needed. Usage of `RuntimeHintsAgent` are also deprecated. Closes gh-33847
1 parent 0759129 commit ba312f6

File tree

31 files changed

+81
-111
lines changed

31 files changed

+81
-111
lines changed
 

‎framework-docs/src/main/java/org/springframework/docs/core/aot/hints/testing/SampleReflectionRuntimeHintsTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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,7 +24,6 @@
2424
import org.springframework.aot.hint.RuntimeHints;
2525
import org.springframework.aot.test.agent.EnabledIfRuntimeHintsAgent;
2626
import org.springframework.aot.test.agent.RuntimeHintsInvocations;
27-
import org.springframework.aot.test.agent.RuntimeHintsRecorder;
2827
import org.springframework.core.SpringVersion;
2928

3029
import static org.assertj.core.api.Assertions.assertThat;
@@ -33,6 +32,7 @@
3332
// method is only enabled if the RuntimeHintsAgent is loaded on the current JVM.
3433
// It also tags tests with the "RuntimeHints" JUnit tag.
3534
@EnabledIfRuntimeHintsAgent
35+
@SuppressWarnings("removal")
3636
class SampleReflectionRuntimeHintsTests {
3737

3838
@Test
@@ -43,7 +43,7 @@ void shouldRegisterReflectionHints() {
4343
typeHint.withMethod("getVersion", List.of(), ExecutableMode.INVOKE));
4444

4545
// Invoke the relevant piece of code we want to test within a recording lambda
46-
RuntimeHintsInvocations invocations = RuntimeHintsRecorder.record(() -> {
46+
RuntimeHintsInvocations invocations = org.springframework.aot.test.agent.RuntimeHintsRecorder.record(() -> {
4747
SampleReflection sample = new SampleReflection();
4848
sample.performReflection();
4949
});

‎integration-tests/src/test/java/org/springframework/aot/test/ReflectionInvocationsTests.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -18,24 +18,23 @@
1818

1919
import org.junit.jupiter.api.Test;
2020

21-
import org.springframework.aot.hint.MemberCategory;
2221
import org.springframework.aot.hint.RuntimeHints;
2322
import org.springframework.aot.test.agent.EnabledIfRuntimeHintsAgent;
2423
import org.springframework.aot.test.agent.RuntimeHintsInvocations;
25-
import org.springframework.aot.test.agent.RuntimeHintsRecorder;
2624

2725
import static org.assertj.core.api.Assertions.assertThat;
2826

2927

3028
@EnabledIfRuntimeHintsAgent
29+
@SuppressWarnings("removal")
3130
class ReflectionInvocationsTests {
3231

3332
@Test
3433
void sampleTest() {
3534
RuntimeHints hints = new RuntimeHints();
36-
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
35+
hints.reflection().registerType(String.class);
3736

38-
RuntimeHintsInvocations invocations = RuntimeHintsRecorder.record(() -> {
37+
RuntimeHintsInvocations invocations = org.springframework.aot.test.agent.RuntimeHintsRecorder.record(() -> {
3938
SampleReflection sample = new SampleReflection();
4039
sample.sample(); // does Method[] methods = String.class.getMethods();
4140
});
@@ -45,9 +44,9 @@ void sampleTest() {
4544
@Test
4645
void multipleCallsTest() {
4746
RuntimeHints hints = new RuntimeHints();
48-
hints.reflection().registerType(String.class, MemberCategory.INTROSPECT_PUBLIC_METHODS);
49-
hints.reflection().registerType(Integer.class,MemberCategory.INTROSPECT_PUBLIC_METHODS);
50-
RuntimeHintsInvocations invocations = RuntimeHintsRecorder.record(() -> {
47+
hints.reflection().registerType(String.class);
48+
hints.reflection().registerType(Integer.class);
49+
RuntimeHintsInvocations invocations = org.springframework.aot.test.agent.RuntimeHintsRecorder.record(() -> {
5150
SampleReflection sample = new SampleReflection();
5251
sample.multipleCalls(); // does Method[] methods = String.class.getMethods(); methods = Integer.class.getMethods();
5352
});

‎spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public AspectJAdvisorContribution(Class<?> beanClass) {
7474

7575
@Override
7676
public void applyTo(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode) {
77-
generationContext.getRuntimeHints().reflection().registerType(this.beanClass, MemberCategory.DECLARED_FIELDS);
77+
generationContext.getRuntimeHints().reflection().registerType(this.beanClass, MemberCategory.INVOKE_DECLARED_FIELDS);
7878
}
7979
}
8080

‎spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AspectJAdvisorBeanRegistrationAotProcessorTests {
4848
@Test
4949
void shouldProcessAspectJClass() {
5050
process(AspectJClass.class);
51-
assertThat(reflection().onType(AspectJClass.class).withMemberCategory(MemberCategory.DECLARED_FIELDS))
51+
assertThat(reflection().onType(AspectJClass.class).withMemberCategory(MemberCategory.INVOKE_DECLARED_FIELDS))
5252
.accepts(this.runtimeHints);
5353
}
5454

‎spring-beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ private CodeBlock generateMethodStatementForMethod(CodeWarnings codeWarnings,
10651065
}
10661066
else {
10671067
codeWarnings.detectDeprecation(method);
1068-
hints.reflection().registerMethod(method, ExecutableMode.INTROSPECT);
1068+
hints.reflection().registerType(method.getDeclaringClass());
10691069
CodeBlock arguments = new AutowiredArgumentsCodeGenerator(this.target,
10701070
method).generateCode(method.getParameterTypes());
10711071
CodeBlock injectionCode = CodeBlock.of("args -> $L.$L($L)",

‎spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,10 @@ private void registerReflectionHints(RootBeanDefinition beanDefinition, Method w
252252
// ReflectionUtils#findField searches recursively in the type hierarchy
253253
Class<?> searchType = beanDefinition.getTargetType();
254254
while (searchType != null && searchType != writeMethod.getDeclaringClass()) {
255-
this.hints.reflection().registerType(searchType, MemberCategory.DECLARED_FIELDS);
255+
this.hints.reflection().registerType(searchType, MemberCategory.INVOKE_DECLARED_FIELDS);
256256
searchType = searchType.getSuperclass();
257257
}
258-
this.hints.reflection().registerType(writeMethod.getDeclaringClass(), MemberCategory.DECLARED_FIELDS);
258+
this.hints.reflection().registerType(writeMethod.getDeclaringClass(), MemberCategory.INVOKE_DECLARED_FIELDS);
259259
}
260260

261261
private void addQualifiers(CodeBlock.Builder code, RootBeanDefinition beanDefinition) {

‎spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContribution.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import org.springframework.aot.generate.GenerationContext;
2727
import org.springframework.aot.generate.MethodReference;
2828
import org.springframework.aot.generate.MethodReference.ArgumentCodeGenerator;
29-
import org.springframework.aot.hint.MemberCategory;
3029
import org.springframework.aot.hint.ReflectionHints;
3130
import org.springframework.aot.hint.RuntimeHints;
31+
import org.springframework.aot.hint.TypeHint;
3232
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
3333
import org.springframework.beans.factory.support.RegisteredBean;
3434
import org.springframework.javapoet.ClassName;
@@ -100,8 +100,8 @@ private void generateRegisterHints(RuntimeHints runtimeHints, List<Registration>
100100
registrations.forEach(registration -> {
101101
ReflectionHints hints = runtimeHints.reflection();
102102
Class<?> beanClass = registration.registeredBean.getBeanClass();
103-
hints.registerType(beanClass, MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS);
104-
hints.registerForInterfaces(beanClass, typeHint -> typeHint.withMembers(MemberCategory.INTROSPECT_PUBLIC_METHODS));
103+
hints.registerType(beanClass);
104+
hints.registerForInterfaces(beanClass, TypeHint.Builder::withMembers);
105105
});
106106
}
107107

‎spring-beans/src/main/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGenerator.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ private CodeBlock generateCodeForConstructor(RegisteredBean registeredBean, Cons
172172
}
173173

174174
private CodeBlock generateCodeForAccessibleConstructor(String beanName, Constructor<?> constructor) {
175-
this.generationContext.getRuntimeHints().reflection().registerConstructor(
176-
constructor, ExecutableMode.INTROSPECT);
175+
this.generationContext.getRuntimeHints().reflection().registerType(constructor.getDeclaringClass());
177176

178177
if (constructor.getParameterCount() == 0) {
179178
if (!this.allowDirectSupplierShortcut) {
@@ -265,7 +264,7 @@ private CodeBlock generateCodeForFactoryMethod(
265264
private CodeBlock generateCodeForAccessibleFactoryMethod(String beanName,
266265
Method factoryMethod, Class<?> targetClass, @Nullable String factoryBeanName) {
267266

268-
this.generationContext.getRuntimeHints().reflection().registerMethod(factoryMethod, ExecutableMode.INTROSPECT);
267+
this.generationContext.getRuntimeHints().reflection().registerType(factoryMethod.getDeclaringClass());
269268

270269
if (factoryBeanName == null && factoryMethod.getParameterCount() == 0) {
271270
Class<?> suppliedType = ClassUtils.resolvePrimitiveIfNecessary(factoryMethod.getReturnType());

‎spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ private void assertHasMethodInvokeHints(Class<?> beanType, String... methodNames
574574

575575
private void assertHasDeclaredFieldsHint(Class<?> beanType) {
576576
assertThat(RuntimeHintsPredicates.reflection()
577-
.onType(beanType).withMemberCategory(MemberCategory.DECLARED_FIELDS))
577+
.onType(beanType).withMemberCategory(MemberCategory.INVOKE_DECLARED_FIELDS))
578578
.accepts(this.generationContext.getRuntimeHints());
579579
}
580580

‎spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.springframework.aot.generate.MethodReference;
3232
import org.springframework.aot.generate.MethodReference.ArgumentCodeGenerator;
3333
import org.springframework.aot.generate.ValueCodeGenerationException;
34-
import org.springframework.aot.hint.MemberCategory;
3534
import org.springframework.aot.test.generate.TestGenerationContext;
3635
import org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.Registration;
3736
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -149,14 +148,11 @@ void applyToRegisterReflectionHints() {
149148
registeredBean, null, List.of());
150149
BeanRegistrationsAotContribution contribution = createContribution(registeredBean, generator);
151150
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
152-
assertThat(reflection().onType(Employee.class)
153-
.withMemberCategories(MemberCategory.INTROSPECT_PUBLIC_METHODS, MemberCategory.INTROSPECT_DECLARED_METHODS))
151+
assertThat(reflection().onType(Employee.class))
154152
.accepts(this.generationContext.getRuntimeHints());
155-
assertThat(reflection().onType(ITestBean.class)
156-
.withMemberCategory(MemberCategory.INTROSPECT_PUBLIC_METHODS))
153+
assertThat(reflection().onType(ITestBean.class))
157154
.accepts(this.generationContext.getRuntimeHints());
158-
assertThat(reflection().onType(AgeHolder.class)
159-
.withMemberCategory(MemberCategory.INTROSPECT_PUBLIC_METHODS))
155+
assertThat(reflection().onType(AgeHolder.class))
160156
.accepts(this.generationContext.getRuntimeHints());
161157
}
162158

‎spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java

+10-20
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ void generateWhenHasDefaultConstructor() {
100100
assertThat(compiled.getSourceFile())
101101
.contains("InstanceSupplier.using(TestBean::new)");
102102
});
103-
assertThat(getReflectionHints().getTypeHint(TestBean.class))
104-
.satisfies(hasConstructorWithMode(ExecutableMode.INTROSPECT));
103+
assertThat(getReflectionHints().getTypeHint(TestBean.class)).isNotNull();
105104
}
106105

107106
@Test
@@ -112,8 +111,7 @@ void generateWhenHasConstructorWithParameter() {
112111
InjectionComponent bean = getBean(beanDefinition, instanceSupplier);
113112
assertThat(bean).isInstanceOf(InjectionComponent.class).extracting("bean").isEqualTo("injected");
114113
});
115-
assertThat(getReflectionHints().getTypeHint(InjectionComponent.class))
116-
.satisfies(hasConstructorWithMode(ExecutableMode.INTROSPECT));
114+
assertThat(getReflectionHints().getTypeHint(InjectionComponent.class)).isNotNull();
117115
}
118116

119117
@Test
@@ -126,8 +124,7 @@ void generateWhenHasConstructorWithInnerClassAndDefaultConstructor() {
126124
assertThat(compiled.getSourceFile()).contains(
127125
"getBeanFactory().getBean(InnerComponentConfiguration.class).new NoDependencyComponent()");
128126
});
129-
assertThat(getReflectionHints().getTypeHint(NoDependencyComponent.class))
130-
.satisfies(hasConstructorWithMode(ExecutableMode.INTROSPECT));
127+
assertThat(getReflectionHints().getTypeHint(NoDependencyComponent.class)).isNotNull();
131128
}
132129

133130
@Test
@@ -141,8 +138,7 @@ void generateWhenHasConstructorWithInnerClassAndParameter() {
141138
assertThat(compiled.getSourceFile()).contains(
142139
"getBeanFactory().getBean(InnerComponentConfiguration.class).new EnvironmentAwareComponent(");
143140
});
144-
assertThat(getReflectionHints().getTypeHint(EnvironmentAwareComponent.class))
145-
.satisfies(hasConstructorWithMode(ExecutableMode.INTROSPECT));
141+
assertThat(getReflectionHints().getTypeHint(EnvironmentAwareComponent.class)).isNotNull();
146142
}
147143

148144
@Test
@@ -184,8 +180,7 @@ void generateWhenHasConstructorWithGeneric() {
184180
assertThat(bean).extracting("number").isNull(); // No property actually set
185181
assertThat(compiled.getSourceFile()).contains("NumberHolderFactoryBean::new");
186182
});
187-
assertThat(getReflectionHints().getTypeHint(NumberHolderFactoryBean.class))
188-
.satisfies(hasConstructorWithMode(ExecutableMode.INTROSPECT));
183+
assertThat(getReflectionHints().getTypeHint(NumberHolderFactoryBean.class)).isNotNull();
189184
}
190185

191186
@Test
@@ -215,8 +210,7 @@ void generateWhenHasFactoryMethodWithNoArg() {
215210
assertThat(compiled.getSourceFile()).contains(
216211
"getBeanFactory().getBean(\"config\", SimpleConfiguration.class).stringBean()");
217212
});
218-
assertThat(getReflectionHints().getTypeHint(SimpleConfiguration.class))
219-
.satisfies(hasMethodWithMode(ExecutableMode.INTROSPECT));
213+
assertThat(getReflectionHints().getTypeHint(SimpleConfiguration.class)).isNotNull();
220214
}
221215

222216
@Test
@@ -232,8 +226,7 @@ void generateWhenHasFactoryMethodOnInterface() {
232226
assertThat(compiled.getSourceFile()).contains(
233227
"getBeanFactory().getBean(\"config\", DefaultSimpleBeanContract.class).simpleBean()");
234228
});
235-
assertThat(getReflectionHints().getTypeHint(SimpleBeanContract.class))
236-
.satisfies(hasMethodWithMode(ExecutableMode.INTROSPECT));
229+
assertThat(getReflectionHints().getTypeHint(SimpleBeanContract.class)).isNotNull();
237230
}
238231

239232
@Test
@@ -268,8 +261,7 @@ void generateWhenHasStaticFactoryMethodWithNoArg() {
268261
assertThat(compiled.getSourceFile())
269262
.contains("(registeredBean) -> SimpleConfiguration.integerBean()");
270263
});
271-
assertThat(getReflectionHints().getTypeHint(SimpleConfiguration.class))
272-
.satisfies(hasMethodWithMode(ExecutableMode.INTROSPECT));
264+
assertThat(getReflectionHints().getTypeHint(SimpleConfiguration.class)).isNotNull();
273265
}
274266

275267
@Test
@@ -287,8 +279,7 @@ void generateWhenHasStaticFactoryMethodWithArg() {
287279
assertThat(bean).isEqualTo("42test");
288280
assertThat(compiled.getSourceFile()).contains("SampleFactory.create(");
289281
});
290-
assertThat(getReflectionHints().getTypeHint(SampleFactory.class))
291-
.satisfies(hasMethodWithMode(ExecutableMode.INTROSPECT));
282+
assertThat(getReflectionHints().getTypeHint(SampleFactory.class)).isNotNull();
292283
}
293284

294285
@Test
@@ -305,8 +296,7 @@ void generateWhenHasFactoryMethodCheckedException() {
305296
assertThat(bean).isEqualTo(42);
306297
assertThat(compiled.getSourceFile()).doesNotContain(") throws Exception {");
307298
});
308-
assertThat(getReflectionHints().getTypeHint(SimpleConfiguration.class))
309-
.satisfies(hasMethodWithMode(ExecutableMode.INTROSPECT));
299+
assertThat(getReflectionHints().getTypeHint(SimpleConfiguration.class)).isNotNull();
310300
}
311301

312302

‎spring-beans/src/test/kotlin/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorKotlinTests.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ class InstanceSupplierCodeGeneratorKotlinTests {
5656
Assertions.assertThat(bean).isInstanceOf(KotlinTestBean::class.java)
5757
Assertions.assertThat(compiled.sourceFile).contains("InstanceSupplier.using(KotlinTestBean::new)")
5858
}
59-
Assertions.assertThat(getReflectionHints().getTypeHint(KotlinTestBean::class.java))
60-
.satisfies(hasConstructorWithMode(ExecutableMode.INTROSPECT))
59+
Assertions.assertThat(getReflectionHints().getTypeHint(KotlinTestBean::class.java)).isNotNull
6160
}
6261

6362
@Test
@@ -90,8 +89,7 @@ class InstanceSupplierCodeGeneratorKotlinTests {
9089
"getBeanFactory().getBean(\"config\", KotlinConfiguration.class).stringBean()"
9190
)
9291
}
93-
Assertions.assertThat<TypeHint?>(getReflectionHints().getTypeHint(KotlinConfiguration::class.java))
94-
.satisfies(hasMethodWithMode(ExecutableMode.INTROSPECT))
92+
Assertions.assertThat<TypeHint?>(getReflectionHints().getTypeHint(KotlinConfiguration::class.java)).isNotNull
9593
}
9694

9795
@Test

‎spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ private CodeBlock generateMethodStatementForMethod(ClassName targetClassName,
960960
return CodeBlock.of("$L.resolveAndSet($L, $L)", resolver,
961961
REGISTERED_BEAN_PARAMETER, INSTANCE_PARAMETER);
962962
}
963-
hints.reflection().registerMethod(method, ExecutableMode.INTROSPECT);
963+
hints.reflection().registerType(method.getDeclaringClass());
964964
return CodeBlock.of("$L.$L($L.resolve($L))", INSTANCE_PARAMETER,
965965
method.getName(), resolver, REGISTERED_BEAN_PARAMETER);
966966

‎spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.springframework.aop.framework.autoproxy.AutoProxyUtils;
4141
import org.springframework.aot.generate.GeneratedMethod;
4242
import org.springframework.aot.generate.GenerationContext;
43-
import org.springframework.aot.hint.ExecutableMode;
4443
import org.springframework.aot.hint.MemberCategory;
4544
import org.springframework.aot.hint.ResourceHints;
4645
import org.springframework.aot.hint.RuntimeHints;
@@ -812,7 +811,7 @@ private InstantiationDescriptor proxyInstantiationDescriptor(
812811
Executable userExecutable = instantiationDescriptor.executable();
813812
if (userExecutable instanceof Constructor<?> userConstructor) {
814813
try {
815-
runtimeHints.reflection().registerConstructor(userConstructor, ExecutableMode.INTROSPECT);
814+
runtimeHints.reflection().registerType(userConstructor.getDeclaringClass());
816815
Constructor<?> constructor = this.proxyClass.getConstructor(userExecutable.getParameterTypes());
817816
return new InstantiationDescriptor(constructor);
818817
}

‎spring-context/src/main/java/org/springframework/context/aot/KotlinReflectionBeanRegistrationAotProcessor.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.context.aot;
1818

1919
import org.springframework.aot.generate.GenerationContext;
20-
import org.springframework.aot.hint.MemberCategory;
2120
import org.springframework.aot.hint.RuntimeHints;
2221
import org.springframework.beans.factory.aot.BeanRegistrationAotContribution;
2322
import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor;
@@ -61,7 +60,7 @@ public void applyTo(GenerationContext generationContext, BeanRegistrationCode be
6160

6261
private void registerHints(Class<?> type, RuntimeHints runtimeHints) {
6362
if (KotlinDetector.isKotlinType(type)) {
64-
runtimeHints.reflection().registerType(type, MemberCategory.INTROSPECT_DECLARED_METHODS);
63+
runtimeHints.reflection().registerType(type);
6564
}
6665
Class<?> superClass = type.getSuperclass();
6766
if (superClass != null) {

‎spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public AotContribution(Collection<Class<?>> validatedClasses,
237237
public void applyTo(GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode) {
238238
ReflectionHints hints = generationContext.getRuntimeHints().reflection();
239239
for (Class<?> validatedClass : this.validatedClasses) {
240-
hints.registerType(validatedClass, MemberCategory.DECLARED_FIELDS);
240+
hints.registerType(validatedClass, MemberCategory.INVOKE_DECLARED_FIELDS);
241241
}
242242
for (Class<? extends ConstraintValidator<?, ?>> constraintValidatorClass : this.constraintValidatorClasses) {
243243
hints.registerType(constraintValidatorClass, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);

‎spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ void refreshForAotRegisterHintsForCglibProxy() {
534534
TypeReference cglibType = TypeReference.of(CglibConfiguration.class.getName() + "$$SpringCGLIB$$0");
535535
assertThat(RuntimeHintsPredicates.reflection().onType(cglibType)
536536
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
537-
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.DECLARED_FIELDS))
537+
MemberCategory.INVOKE_DECLARED_METHODS, MemberCategory.INVOKE_DECLARED_FIELDS))
538538
.accepts(runtimeHints);
539539
assertThat(RuntimeHintsPredicates.reflection().onType(CglibConfiguration.class)
540540
.withMemberCategories(MemberCategory.INVOKE_PUBLIC_METHODS, MemberCategory.INVOKE_DECLARED_METHODS))

‎spring-context/src/test/java/org/springframework/context/aot/ContextAotProcessorTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -102,7 +102,7 @@ private Consumer<Path> hasGeneratedAssetsForSampleApplication() {
102102
assertThat(directory.resolve(
103103
"source/org/springframework/context/aot/ContextAotProcessorTests_SampleApplication__BeanFactoryRegistrations.java"))
104104
.exists().isRegularFile();
105-
assertThat(directory.resolve("resource/META-INF/native-image/com.example/example/reflect-config.json"))
105+
assertThat(directory.resolve("resource/META-INF/native-image/com.example/example/reachability-metadata.json"))
106106
.exists().isRegularFile();
107107
Path nativeImagePropertiesFile = directory
108108
.resolve("resource/META-INF/native-image/com.example/example/native-image.properties");

0 commit comments

Comments
 (0)
Please sign in to comment.