Skip to content

Commit 4010958

Browse files
committed
Add missing AOT hints for Spring Batch integration module
Resolves #4307
1 parent 0103ef0 commit 4010958

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

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

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,17 @@
2929
import java.util.Calendar;
3030
import java.util.Date;
3131
import java.util.HashMap;
32+
import java.util.HashSet;
3233
import java.util.Hashtable;
34+
import java.util.LinkedHashMap;
35+
import java.util.LinkedHashSet;
3336
import java.util.Properties;
37+
import java.util.Set;
3438
import java.util.UUID;
39+
import java.util.concurrent.ConcurrentHashMap;
40+
import java.util.concurrent.locks.AbstractOwnableSynchronizer;
41+
import java.util.concurrent.locks.AbstractQueuedSynchronizer;
42+
import java.util.concurrent.locks.ReentrantLock;
3543
import java.util.stream.Stream;
3644

3745
import org.springframework.aop.SpringProxy;
@@ -41,8 +49,18 @@
4149
import org.springframework.aot.hint.RuntimeHintsRegistrar;
4250
import org.springframework.aot.hint.SerializationHints;
4351
import org.springframework.aot.hint.TypeReference;
52+
import org.springframework.batch.core.Entity;
53+
import org.springframework.batch.core.ExitStatus;
54+
import org.springframework.batch.core.JobExecution;
55+
import org.springframework.batch.core.JobInstance;
56+
import org.springframework.batch.core.JobParameter;
57+
import org.springframework.batch.core.JobParameters;
58+
import org.springframework.batch.core.StepContribution;
59+
import org.springframework.batch.core.StepExecution;
4460
import org.springframework.batch.core.scope.context.JobContext;
4561
import org.springframework.batch.core.scope.context.StepContext;
62+
import org.springframework.batch.item.Chunk;
63+
import org.springframework.batch.item.ExecutionContext;
4664
import org.springframework.core.DecoratingProxy;
4765

4866
/**
@@ -58,6 +76,12 @@ public class CoreRuntimeHints implements RuntimeHintsRegistrar {
5876
@Override
5977
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
6078

79+
Set<String> jdkTypes = Set.of("java.time.Ser", "java.util.Collections$SynchronizedSet",
80+
"java.util.Collections$SynchronizedCollection", "java.util.concurrent.locks.ReentrantLock$Sync",
81+
"java.util.concurrent.locks.ReentrantLock$FairSync",
82+
"java.util.concurrent.locks.ReentrantLock$NonfairSync",
83+
"java.util.concurrent.ConcurrentHashMap$Segment");
84+
6185
// resource hints
6286
hints.resources().registerPattern("org/springframework/batch/core/schema-h2.sql");
6387
hints.resources().registerPattern("org/springframework/batch/core/schema-derby.sql");
@@ -88,14 +112,31 @@ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
88112
hints.reflection().registerType(Types.class, MemberCategory.DECLARED_FIELDS);
89113
hints.reflection().registerType(JobContext.class, MemberCategory.INVOKE_PUBLIC_METHODS);
90114
hints.reflection().registerType(StepContext.class, MemberCategory.INVOKE_PUBLIC_METHODS);
115+
hints.reflection().registerType(JobParameter.class, MemberCategory.values());
116+
hints.reflection().registerType(JobParameters.class, MemberCategory.values());
117+
hints.reflection().registerType(ExitStatus.class, MemberCategory.values());
118+
hints.reflection().registerType(JobInstance.class, MemberCategory.values());
119+
hints.reflection().registerType(JobExecution.class, MemberCategory.values());
120+
hints.reflection().registerType(StepExecution.class, MemberCategory.values());
121+
hints.reflection().registerType(StepContribution.class, MemberCategory.values());
122+
hints.reflection().registerType(Entity.class, MemberCategory.values());
123+
hints.reflection().registerType(ExecutionContext.class, MemberCategory.values());
124+
hints.reflection().registerType(Chunk.class, MemberCategory.values());
125+
jdkTypes.stream().map(TypeReference::of)
126+
.forEach(type -> hints.reflection().registerType(type, MemberCategory.values()));
91127

92128
// serialization hints
93129
SerializationHints serializationHints = hints.serialization();
94-
Stream.of(Number.class, Byte.class, Short.class, Integer.class, Long.class, Double.class, Float.class,
95-
Character.class, String.class, Boolean.class, Date.class, Calendar.class, LocalDate.class,
96-
LocalTime.class, LocalDateTime.class, OffsetTime.class, OffsetDateTime.class, ZonedDateTime.class,
97-
Instant.class, Duration.class, Period.class, HashMap.class, Hashtable.class, ArrayList.class,
98-
Properties.class, Exception.class, UUID.class).forEach(serializationHints::registerType);
130+
Stream.of(LinkedHashSet.class, LinkedHashMap.class, HashSet.class, ReentrantLock.class, ConcurrentHashMap.class,
131+
AbstractOwnableSynchronizer.class, AbstractQueuedSynchronizer.class, Number.class, Byte.class,
132+
Short.class, Integer.class, Long.class, Double.class, Float.class, Character.class, String.class,
133+
Boolean.class, Date.class, Calendar.class, LocalDate.class, LocalTime.class, LocalDateTime.class,
134+
OffsetTime.class, OffsetDateTime.class, ZonedDateTime.class, Instant.class, Duration.class,
135+
Period.class, HashMap.class, Hashtable.class, ArrayList.class, JobParameter.class, JobParameters.class,
136+
ExitStatus.class, JobInstance.class, JobExecution.class, StepExecution.class, StepContribution.class,
137+
Entity.class, ExecutionContext.class, Chunk.class, Properties.class, Exception.class, UUID.class)
138+
.forEach(serializationHints::registerType);
139+
jdkTypes.stream().map(TypeReference::of).forEach(serializationHints::registerType);
99140
}
100141

101142
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.aot.hint.RuntimeHintsRegistrar=org.springframework.batch.integration.aot.IntegrationRuntimeHints
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.batch.integration.aot;
17+
18+
import org.springframework.aot.hint.MemberCategory;
19+
import org.springframework.aot.hint.RuntimeHints;
20+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
21+
import org.springframework.batch.integration.chunk.ChunkRequest;
22+
import org.springframework.batch.integration.chunk.ChunkResponse;
23+
24+
/**
25+
* AOT hints for Spring Batch integration module.
26+
*
27+
* @author Mahmoud Ben Hassine
28+
* @since 5.0.1
29+
*/
30+
public class IntegrationRuntimeHints implements RuntimeHintsRegistrar {
31+
32+
@Override
33+
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
34+
// reflection hints
35+
hints.reflection().registerType(ChunkRequest.class, MemberCategory.values());
36+
hints.reflection().registerType(ChunkResponse.class, MemberCategory.values());
37+
38+
// serialization hints
39+
hints.serialization().registerType(ChunkRequest.class);
40+
hints.serialization().registerType(ChunkResponse.class);
41+
}
42+
43+
}

0 commit comments

Comments
 (0)