Skip to content

Commit 82d2b7c

Browse files
committed
Add reflection hints for methods in Job/Step context
Issue #5041 (cherry picked from commit ddf34d3)
1 parent 966b7f4 commit 82d2b7c

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;
@@ -62,6 +65,8 @@
6265
import org.springframework.batch.item.Chunk;
6366
import org.springframework.batch.item.ExecutionContext;
6467
import org.springframework.core.DecoratingProxy;
68+
import org.springframework.util.Assert;
69+
import org.springframework.util.ReflectionUtils;
6570

6671
/**
6772
* {@link RuntimeHintsRegistrar} for Spring Batch core module.
@@ -129,7 +134,7 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
129134
.proxiedInterfaces(TypeReference.of("org.springframework.batch.core.launch.JobOperator"))
130135
.proxiedInterfaces(SpringProxy.class, Advised.class, DecoratingProxy.class));
131136

132-
// reflection hints
137+
// reflection hints: types
133138
hints.reflection().registerType(Types.class, MemberCategory.DECLARED_FIELDS);
134139
hints.reflection().registerType(JobContext.class, MemberCategory.INVOKE_PUBLIC_METHODS);
135140
hints.reflection().registerType(StepContext.class, MemberCategory.INVOKE_PUBLIC_METHODS);
@@ -147,6 +152,15 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
147152
.map(TypeReference::of)
148153
.forEach(type -> hints.reflection().registerType(type, MemberCategory.values()));
149154

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

0 commit comments

Comments
 (0)