ItemReader
Reads items one at a time from any data source (CSV, JSON, XML, databases). View ItemReader API →
Ce contenu n’est pas encore disponible dans votre langue.
Spring Batch RS is built around four core traits that define the batch processing model.
graph TD
subgraph "Core Traits"
IR[ItemReader<I>]
IP[ItemProcessor<I, O>]
IW[ItemWriter<O>]
T[Tasklet]
end
subgraph "Data Flow"
IR -->|"read() -> Option<I>"| IP
IP -->|"process(&I) -> O"| IW
IW -->|"write(&[O])"| Output[Output]
end
subgraph "Single Task"
T -->|"execute()"| Result[Result]
end
ItemReader
Reads items one at a time from any data source (CSV, JSON, XML, databases). View ItemReader API →
ItemProcessor
Transforms items from input type to output type. Optional in the pipeline. View ItemProcessor API →
ItemWriter
Writes batches of items to any destination (files, databases, APIs). View ItemWriter API →
Tasklet
Executes single-task operations outside the chunk-oriented model. View Tasklet API →
| Trait | Method | Returns | Purpose |
|---|---|---|---|
ItemReader<I> | read(&self) | Result<Option<I>, BatchError> | Read next item |
ItemProcessor<I,O> | process(&self, &I) | Result<O, BatchError> | Transform item |
ItemWriter<O> | write(&self, &[O]) | Result<(), BatchError> | Write batch |
ItemWriter<O> | open(&self) | Result<(), BatchError> | Initialize writer |
ItemWriter<O> | close(&self) | Result<(), BatchError> | Finalize writer |
ItemWriter<O> | flush(&self) | Result<(), BatchError> | Flush buffers |
pub type ItemReaderResult<I> = Result<Option<I>, BatchError>;pub type ItemProcessorResult<O> = Result<O, BatchError>;pub type ItemWriterResult = Result<(), BatchError>;| Feature | Reader | Description |
|---|---|---|
csv | CsvItemReader<R> | CSV files and strings |
json | JsonItemReader<I, R> | Streaming JSON arrays |
xml | XmlItemReader<R, I> | XML documents |
rdbc-postgres | PostgresRdbcItemReader<I> | PostgreSQL queries |
rdbc-mysql | MysqlRdbcItemReader<I> | MySQL/MariaDB queries |
rdbc-sqlite | SqliteRdbcItemReader<I> | SQLite queries |
mongodb | MongodbItemReader<I> | MongoDB collections |
orm | OrmItemReader<I> | SeaORM entities |
fake | PersonReader | Fake test data |
| Feature | Writer | Description |
|---|---|---|
csv | CsvItemWriter<O, W> | CSV files |
json | JsonItemWriter<O, W> | JSON arrays |
xml | XmlItemWriter<O, W> | XML documents |
rdbc-postgres | PostgresItemWriter<O> | PostgreSQL inserts |
rdbc-mysql | MysqlItemWriter<O> | MySQL inserts |
rdbc-sqlite | SqliteItemWriter<O> | SQLite inserts |
mongodb | MongodbItemWriter<O> | MongoDB inserts |
orm | OrmItemWriter<O> | SeaORM inserts |
logger | LoggerWriter | Debug logging |