|
| 1 | +/* |
| 2 | + * Copyright 2025 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.infrastructure.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.item.ItemStreamSupport; |
| 22 | +import org.springframework.batch.item.amqp.AmqpItemReader; |
| 23 | +import org.springframework.batch.item.amqp.AmqpItemWriter; |
| 24 | +import org.springframework.batch.item.amqp.builder.AmqpItemReaderBuilder; |
| 25 | +import org.springframework.batch.item.amqp.builder.AmqpItemWriterBuilder; |
| 26 | +import org.springframework.batch.item.database.JdbcBatchItemWriter; |
| 27 | +import org.springframework.batch.item.database.JdbcCursorItemReader; |
| 28 | +import org.springframework.batch.item.database.JdbcPagingItemReader; |
| 29 | +import org.springframework.batch.item.database.JpaCursorItemReader; |
| 30 | +import org.springframework.batch.item.database.JpaItemWriter; |
| 31 | +import org.springframework.batch.item.database.JpaPagingItemReader; |
| 32 | +import org.springframework.batch.item.database.builder.JdbcBatchItemWriterBuilder; |
| 33 | +import org.springframework.batch.item.database.builder.JdbcCursorItemReaderBuilder; |
| 34 | +import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder; |
| 35 | +import org.springframework.batch.item.database.builder.JpaCursorItemReaderBuilder; |
| 36 | +import org.springframework.batch.item.database.builder.JpaItemWriterBuilder; |
| 37 | +import org.springframework.batch.item.database.builder.JpaPagingItemReaderBuilder; |
| 38 | +import org.springframework.batch.item.file.FlatFileItemReader; |
| 39 | +import org.springframework.batch.item.file.FlatFileItemWriter; |
| 40 | +import org.springframework.batch.item.file.builder.FlatFileItemReaderBuilder; |
| 41 | +import org.springframework.batch.item.file.builder.FlatFileItemWriterBuilder; |
| 42 | +import org.springframework.batch.item.jms.JmsItemReader; |
| 43 | +import org.springframework.batch.item.jms.JmsItemWriter; |
| 44 | +import org.springframework.batch.item.jms.builder.JmsItemReaderBuilder; |
| 45 | +import org.springframework.batch.item.jms.builder.JmsItemWriterBuilder; |
| 46 | +import org.springframework.batch.item.json.JsonFileItemWriter; |
| 47 | +import org.springframework.batch.item.json.JsonItemReader; |
| 48 | +import org.springframework.batch.item.json.builder.JsonFileItemWriterBuilder; |
| 49 | +import org.springframework.batch.item.json.builder.JsonItemReaderBuilder; |
| 50 | +import org.springframework.batch.item.queue.BlockingQueueItemReader; |
| 51 | +import org.springframework.batch.item.queue.BlockingQueueItemWriter; |
| 52 | +import org.springframework.batch.item.queue.builder.BlockingQueueItemReaderBuilder; |
| 53 | +import org.springframework.batch.item.queue.builder.BlockingQueueItemWriterBuilder; |
| 54 | +import org.springframework.batch.item.support.AbstractFileItemWriter; |
| 55 | +import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader; |
| 56 | +import org.springframework.batch.item.support.AbstractItemStreamItemReader; |
| 57 | +import org.springframework.batch.item.support.AbstractItemStreamItemWriter; |
| 58 | +import org.springframework.batch.item.xml.StaxEventItemReader; |
| 59 | +import org.springframework.batch.item.xml.StaxEventItemWriter; |
| 60 | +import org.springframework.batch.item.xml.builder.StaxEventItemReaderBuilder; |
| 61 | +import org.springframework.batch.item.xml.builder.StaxEventItemWriterBuilder; |
| 62 | + |
| 63 | +import java.util.Set; |
| 64 | + |
| 65 | +/** |
| 66 | + * {@link RuntimeHintsRegistrar} for Spring Batch infrastructure module. |
| 67 | + * |
| 68 | + * @author Mahmoud Ben Hassine |
| 69 | + * @since 5.2.2 |
| 70 | + */ |
| 71 | +public class InfrastructureRuntimeHints implements RuntimeHintsRegistrar { |
| 72 | + |
| 73 | + @Override |
| 74 | + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { |
| 75 | + // reflection hints |
| 76 | + Set<Class<?>> classes = Set.of( |
| 77 | + // File IO APIs |
| 78 | + FlatFileItemReader.class, FlatFileItemReaderBuilder.class, FlatFileItemWriter.class, |
| 79 | + FlatFileItemWriterBuilder.class, JsonItemReader.class, JsonItemReaderBuilder.class, |
| 80 | + JsonFileItemWriter.class, JsonFileItemWriterBuilder.class, StaxEventItemReader.class, |
| 81 | + StaxEventItemReaderBuilder.class, StaxEventItemWriter.class, StaxEventItemWriterBuilder.class, |
| 82 | + |
| 83 | + // Database IO APIs |
| 84 | + JdbcCursorItemReader.class, JdbcCursorItemReaderBuilder.class, JdbcPagingItemReader.class, |
| 85 | + JdbcPagingItemReaderBuilder.class, JdbcBatchItemWriter.class, JdbcBatchItemWriterBuilder.class, |
| 86 | + JpaCursorItemReader.class, JpaCursorItemReaderBuilder.class, JpaPagingItemReader.class, |
| 87 | + JpaPagingItemReaderBuilder.class, JpaItemWriter.class, JpaItemWriterBuilder.class, |
| 88 | + |
| 89 | + // Queue IO APIs |
| 90 | + BlockingQueueItemReader.class, BlockingQueueItemReaderBuilder.class, BlockingQueueItemWriter.class, |
| 91 | + BlockingQueueItemWriterBuilder.class, JmsItemReader.class, JmsItemReaderBuilder.class, |
| 92 | + JmsItemWriter.class, JmsItemWriterBuilder.class, AmqpItemReader.class, AmqpItemReaderBuilder.class, |
| 93 | + AmqpItemWriter.class, AmqpItemWriterBuilder.class, |
| 94 | + |
| 95 | + // Support classes |
| 96 | + AbstractFileItemWriter.class, AbstractItemStreamItemWriter.class, |
| 97 | + AbstractItemCountingItemStreamItemReader.class, AbstractItemStreamItemReader.class, |
| 98 | + ItemStreamSupport.class); |
| 99 | + for (Class<?> type : classes) { |
| 100 | + hints.reflection().registerType(type, MemberCategory.values()); |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | +} |
0 commit comments