Skip to content

Commit ddf34d3

Browse files
committed
Add reflection hints for methods in Job/Step context
Issue #5041
1 parent b23e307 commit ddf34d3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/aot/CoreRuntimeHints.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.batch.core.aot;
1717

18+
import java.lang.reflect.Method;
1819
import java.sql.Types;
1920
import java.time.Duration;
2021
import java.time.Instant;
@@ -33,6 +34,7 @@
3334
import java.util.Hashtable;
3435
import java.util.LinkedHashMap;
3536
import java.util.LinkedHashSet;
37+
import java.util.List;
3638
import java.util.Properties;
3739
import java.util.Set;
3840
import java.util.UUID;
@@ -44,6 +46,7 @@
4446

4547
import org.springframework.aop.SpringProxy;
4648
import org.springframework.aop.framework.Advised;
49+
import org.springframework.aot.hint.ExecutableMode;
4750
import org.springframework.aot.hint.MemberCategory;
4851
import org.springframework.aot.hint.RuntimeHints;
4952
import org.springframework.aot.hint.RuntimeHintsRegistrar;
@@ -72,6 +75,8 @@
7275
import org.springframework.batch.infrastructure.item.Chunk;
7376
import org.springframework.batch.infrastructure.item.ExecutionContext;
7477
import org.springframework.core.DecoratingProxy;
78+
import org.springframework.util.Assert;
79+
import org.springframework.util.ReflectionUtils;
7580

7681
/**
7782
* {@link RuntimeHintsRegistrar} for Spring Batch core module.
@@ -131,7 +136,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
131136
.registerJdkProxy(builder -> builder.proxiedInterfaces(TypeReference.of(JobOperator.class))
132137
.proxiedInterfaces(SpringProxy.class, Advised.class, DecoratingProxy.class));
133138

134-
// reflection hints
139+
// reflection hints: types
135140
hints.reflection().registerType(Types.class);
136141
hints.reflection().registerType(JobContext.class);
137142
hints.reflection().registerType(StepContext.class);
@@ -149,6 +154,15 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
149154
.map(TypeReference::of)
150155
.forEach(type -> hints.reflection().registerType(type, MemberCategory.values()));
151156

157+
// reflection hints: methods
158+
Method jobContextGetJobParametersMethod = ReflectionUtils.findMethod(JobContext.class, "getJobParameters");
159+
Assert.state(jobContextGetJobParametersMethod != null, "JobContext#getJobParameters must not be null");
160+
Method stepContextGetJobParametersMethod = ReflectionUtils.findMethod(StepContext.class, "getJobParameters");
161+
Assert.state(stepContextGetJobParametersMethod != null, "StepContext#getJobParameters must not be null");
162+
163+
List<Method> methods = List.of(jobContextGetJobParametersMethod, stepContextGetJobParametersMethod);
164+
methods.forEach(method -> hints.reflection().registerMethod(method, ExecutableMode.INVOKE));
165+
152166
// serialization hints
153167
SerializationHints serializationHints = hints.serialization();
154168
Stream.of(LinkedHashSet.class, LinkedHashMap.class, HashSet.class, ReentrantLock.class, ConcurrentHashMap.class,

0 commit comments

Comments
 (0)